Skip to content

Commit d607bb2

Browse files
committed
Time: 286 ms (30.43%), Space: 27.4 MB (39.86%) - LeetHub
1 parent fc8591d commit d607bb2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def minDifference(self, nums: List[int]) -> int:
3+
#if length of nums is less than four then the result will always 0
4+
#bcoz from 4 elements 3 will be removed and min difference of same number is 0.
5+
if len(nums)<=4:
6+
return 0
7+
nums.sort()
8+
result=float('inf')
9+
for l in range(4):
10+
r=len(nums)-4+l
11+
result=min(result,nums[r]-nums[l])
12+
13+
return result
14+

0 commit comments

Comments
 (0)