Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion solutions/python/practice294.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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!")
Loading