diff --git a/solutions/python/practice294.py b/solutions/python/practice294.py index cfa46aa..1372597 100644 --- a/solutions/python/practice294.py +++ b/solutions/python/practice294.py @@ -1,4 +1,3 @@ -# Minimum Distance to the Target Element # Problem: Minimum Distance to the Target Element # Source: https://leetcode.com/problems/minimum-distance-to-the-target-element/ # Note: Finds the minimum absolute distance between start and an index containing target. @@ -14,3 +13,12 @@ def getMinDistance(self, nums, target, start): closest = min(closest, abs(start - i)) return closest +# Test cases +sol = Solution() +assert sol.getMinDistance([1, 2, 3, 4, 5], 5, 3) == 1 +assert sol.getMinDistance([1], 1, 0) == 0 +assert sol.getMinDistance([1, 1, 1, 1, 1], 1, 0) == 0 +assert sol.getMinDistance([5, 3, 6], 5, 2) == 2 +assert sol.getMinDistance([1, 2, 3, 4, 5, 3], 3, 4) == 1 + +print("All test cases passed!")