post_href stringlengths 57 213 | python_solutions stringlengths 71 22.3k | slug stringlengths 3 77 | post_title stringlengths 1 100 | user stringlengths 3 29 | upvotes int64 -20 1.2k | views int64 0 60.9k | problem_title stringlengths 3 77 | number int64 1 2.48k | acceptance float64 0.14 0.91 | difficulty stringclasses 3
values | __index_level_0__ int64 0 34k |
|---|---|---|---|---|---|---|---|---|---|---|---|
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/2082479/java-python-easy | class Solution:
def minimumSum(self, num: int) -> int:
digits = []
while num != 0 :
digits.append(num % 10)
num //= 10
digits.sort()
return (digits[0] + digits[1])*10 + digits[2] + digits[3] | minimum-sum-of-four-digit-number-after-splitting-digits | java, python - easy | ZX007java | 0 | 135 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,000 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1988944/Python-Solution-or-Simple-Sorting-Based-or-Straight-Forward-Solution | class Solution:
def minimumSum(self, num: int) -> int:
num = sorted(str(num))
return (int(num[0]) * 10) + int(num[3]) + (int(num[1]) * 10) + int(num[2]) | minimum-sum-of-four-digit-number-after-splitting-digits | Python Solution | Simple Sorting Based | Straight-Forward Solution | Gautam_ProMax | 0 | 89 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,001 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1884080/Python3-simple-solution | class Solution:
def minimumSum(self, num: int) -> int:
num = str(num)
l = [int(num[0]),int(num[1]),int(num[2]),int(num[3])]
l.sort()
return (l[0]*10 + l[3]) + (l[1]*10 + l[2]) | minimum-sum-of-four-digit-number-after-splitting-digits | Python3 simple solution | EklavyaJoshi | 0 | 55 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,002 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1863176/Python-easy-solution-by-sorting-digits | class Solution:
def minimumSum(self, num: int) -> int:
num_str = sorted(str(num))
return int(num_str[0] + num_str[2]) + int(num_str[1] + num_str[3]) | minimum-sum-of-four-digit-number-after-splitting-digits | Python easy solution by sorting digits | alishak1999 | 0 | 77 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,003 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1838025/Using-list-and-sorting | class Solution:
def minimumSum(self, num: int) -> int:
l = []
while num:
n = num%10
l.append(n)
num = num//10
l.sort()
num1 = num2 = 0
num1 = (num1+l[0])*10+(l[2])
num2 = (num2+l[1])*10+(l[3])
retu... | minimum-sum-of-four-digit-number-after-splitting-digits | Using list and sorting | prajwalahluwalia | 0 | 45 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,004 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1802163/Python-16ms-solution | class Solution:
def minimumSum(self, num: int) -> int:
yst=list(str(num))
yst.sort()
x,y=int(yst[0]+yst[3]),int(yst[1]+yst[2])
return x+y | minimum-sum-of-four-digit-number-after-splitting-digits | Python 16ms solution | AjayKadiri | 0 | 85 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,005 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1764364/Python-95-Faster.-Simple-Solution-with-comments | class Solution:
def minimumSum(self, num: int) -> int:
#break down the number into 4 elements in a list sort asc
sl = sorted(list(str(num)))
#combine positions [0,3] and [1,2] of the list and sum it
return(int(sl[0] + sl[3])+int(sl[1] + sl[2])) | minimum-sum-of-four-digit-number-after-splitting-digits | Python 95% Faster. Simple Solution with comments | ovidaure | 0 | 105 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,006 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1761625/Python-easy-commented-solution | class Solution:
def minimumSum(self, num: int) -> int:
# Making num a string in order to operate with the digits later
num = str(num)
new1, new2 = '', ''
aux = []
final = []
# Appending digits to the list to sort it later
for i in num:
aux.append(int(i)... | minimum-sum-of-four-digit-number-after-splitting-digits | Python easy commented solution | alexmeaun99 | 0 | 54 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,007 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1754704/Absolute-abomination-of-an-answer-(Top-95) | class Solution:
def minimumSum(self, num: int) -> int:
numlist = sorted(str(num))
return ((int(numlist[0])*10)+int(numlist[3]))+((int(numlist[1])*10)+int(numlist[2])) | minimum-sum-of-four-digit-number-after-splitting-digits | Absolute abomination of an answer (Top 95%) | griggs0445 | 0 | 47 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,008 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1752600/Python3-one-liner-sort%2Bgreedy | class Solution:
def minimumSum(self, num: int) -> int:
return sum(w*int(d) for w,d in zip([10,10,1,1],sorted(str(num)))) | minimum-sum-of-four-digit-number-after-splitting-digits | Python3 one-liner, sort+greedy | vsavkin | 0 | 36 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,009 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1749342/My-python-solution | class Solution:
def minimumSum(self, num: int) -> int:
new_arr = []
number1 = ""
number2 = ""
summ = 0
num_str = str(num)
for digit in num_str:
new_arr.append(digit)
new_arr.sort()
number1 += new_arr[0]
number1 += new_arr[2]
... | minimum-sum-of-four-digit-number-after-splitting-digits | My python solution | andrew_fd | 0 | 37 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,010 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1748608/Python-Simple-and-Clean-Python-Solution-by-creating-all-permutations | class Solution:
def minimumSum(self, num: int) -> int:
from itertools import permutations
n=[]
for i in str(num):
n.append(i)
comb = permutations(n, 4)
ans=10000000000000
for t in comb:
a=list(t)
for i in range(1,len(a)):
ans=min(ans,int(''.join(a[:i]))+int(''.join(a[i:])) )
return ans | minimum-sum-of-four-digit-number-after-splitting-digits | [ Python ] ✔✔ Simple and Clean Python Solution by creating all permutations | ASHOK_KUMAR_MEGHVANSHI | 0 | 47 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,011 |
https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/discuss/1747704/Python-or-Straightforward-or-Simple | class Solution:
def minimumSum(self, num: int) -> int:
string = str(num)
arr = [char for char in string]
arr.sort()
# two possible combination
result1 = int(arr[0]+ arr[2]) + int(arr[1] + arr[3])
result2 = int(arr[1]+ arr[2]) + int(arr[0] + arr[3])
... | minimum-sum-of-four-digit-number-after-splitting-digits | Python | Straightforward | Simple | Mikey98 | 0 | 31 | minimum sum of four digit number after splitting digits | 2,160 | 0.879 | Easy | 30,012 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1748566/Python-Simple-and-Clean-Python-Solution-by-Removing-and-Appending | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
ans=[]
nums.remove(pivot)
i=0
ans.append(pivot)
for j in nums:
if j<pivot:
ans.insert(i,j)
i=i+1
elif j==pivot:
ans.insert(i+1,j)
else:
ans.append(j)
return ans | partition-array-according-to-given-pivot | [ Python ] ✔✔ Simple and Clean Python Solution by Removing and Appending | ASHOK_KUMAR_MEGHVANSHI | 5 | 475 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,013 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2082649/java-python3-easy-to-understand | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less = 0
equal = 0
for n in nums :
if n < pivot : less += 1
elif n == pivot : equal += 1
greater = less + equal
equal = less
less = 0
ans = [0]*len(nums)
for n in nu... | partition-array-according-to-given-pivot | java, python3 - easy to understand | ZX007PI | 1 | 121 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,014 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1747309/Simple-Python-Solution-in-O(N)-Time | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less = []
greater = []
equal = []
for n in nums:
if n < pivot:
less.append(n)
elif n > pivot:
greater.append(n)
else:
... | partition-array-according-to-given-pivot | Simple Python Solution in O(N) Time | a_knotty_mathematician | 1 | 78 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,015 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2820953/O(n)-really-easy-to-understand-solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
#left side:
i = 0
left = []
while i < len(nums):
if nums[i] < pivot:
left.append(nums[i])
i += 1
#right side:
i = 0
right = []
... | partition-array-according-to-given-pivot | O(n) really easy to understand solution | khaled_achech | 0 | 5 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,016 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2820205/Python3-solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
lesser = []
greater = []
for num in nums:
if (num < pivot):
lesser.append(num)
elif num > pivot:
greater.append(num)
return lesser + ([pivot] * nums... | partition-array-according-to-given-pivot | Python3 solution | SupriyaArali | 0 | 2 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,017 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2814639/Python-or-O(n)-or-Easy-to-understand-or-Basic-logic | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
l1 = []
l2 = []
l3 = []
for i in nums:
if i < pivot:
l1 += [i]
elif i > pivot:
l3 += [i]
else:
l2 += [pivot]
l =... | partition-array-according-to-given-pivot | Python | O(n) | Easy to understand | Basic logic | bhuvneshwar906 | 0 | 4 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,018 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2804954/Python-Solution-EASY-TO-UNDERSTAND | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
l=[]
r=[]
p=[]
for i in nums:
if i<pivot:
l.append(i)
for i in nums:
if i>pivot:
r.append(i)
for i in nums:
if i==pivot:... | partition-array-according-to-given-pivot | Python Solution - EASY TO UNDERSTAND | T1n1_B0x1 | 0 | 4 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,019 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2789596/Easy-to-understand-Python-solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
count, arr = 0, []
for num in nums:
if num < pivot:
arr.append(num)
elif num == pivot:
count += 1
arr.extend([pivot] * count)
... | partition-array-according-to-given-pivot | Easy to understand Python solution | Aayush3014 | 0 | 5 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,020 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2788969/Basic-python-solutionor-easy-to-understand-or-O(n) | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
left = []
right = []
pivots = []
for i in nums:
if i<pivot:
left.append(i)
elif i > pivot:
right.append(i)
else:
pivots... | partition-array-according-to-given-pivot | Basic python solution| easy to understand | O(n) | sheetalpatne | 0 | 5 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,021 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2788711/Python-1-line-code | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return [x for x in nums if x<pivot]+[pivot]*(nums.count(pivot))+[t for t in nums if t>pivot] | partition-array-according-to-given-pivot | Python 1 line code | kumar_anand05 | 0 | 2 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,022 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2772811/Python-simple-one-liner | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return [i for i in nums if i<pivot]+[i for i in nums if i==pivot]+[i for i in nums if i>pivot] | partition-array-according-to-given-pivot | Python simple one liner | Jishnu_69 | 0 | 4 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,023 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2751978/Simple-Python-Solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less = []; equal = []; greater = []
for i in nums:
if (i < pivot): less.append(i);
for i in nums:
if (i == pivot): equal.append(i);
for i in nums:
if (i > pivot): great... | partition-array-according-to-given-pivot | Simple Python Solution | avinashdoddi2001 | 0 | 5 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,024 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2718032/Python3-solution-clean-code-with-full-comments.-93.55-space. | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
queue_1 = [] # Queue for integers that are smaller than pivot.
queue_2 = [] # Queue for integers that are bigger than pivot.
queue_p = [] # Queue for integers that are equal to the pivot value.
... | partition-array-according-to-given-pivot | Python3 solution, clean code with full comments. 93.55% space. | 375d | 0 | 20 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,025 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2698299/Python3-Simple-Solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
res = []
for n in nums:
if n < pivot: res.append(n)
for n in nums:
if n == pivot: res.append(n)
for n in nums:
if n > pivot: ... | partition-array-according-to-given-pivot | Python3 Simple Solution | mediocre-coder | 0 | 2 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,026 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2693509/Python3-One-Liner-(Silly) | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return [i for i in nums if i < pivot] + [i for i in nums if i == pivot] + [i for i in nums if i > pivot] | partition-array-according-to-given-pivot | Python3 One Liner (Silly) | godshiva | 0 | 8 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,027 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2670168/Python3-one-line-solution!-time-complexity-beats-92.17 | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return [x for x in nums if x < pivot] + [x for x in nums if x == pivot] + [x for x in nums if x > pivot] | partition-array-according-to-given-pivot | Python3 one-line solution! time complexity beats 92.17% | sipi09 | 0 | 6 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,028 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2665862/Python-O(N) | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
left = []
right = []
middle = []
for i in range(len(nums)):
if nums[i] < pivot:
left.append(nums[i])
elif nums[i] > pivot:
right.append(nums[i])
... | partition-array-according-to-given-pivot | Python O(N) | Noisy47 | 0 | 6 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,029 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2659921/Partition-Array-According-to-Given-Pivot-oror-Python3 | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
l=[]
s=[]
h=[]
for i in nums:
if i<pivot:
l.append(i)
elif i>pivot:
h.append(i)
else:
s.append(i)
return l+s+h | partition-array-according-to-given-pivot | Partition Array According to Given Pivot || Python3 | shagun_pandey | 0 | 7 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,030 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2642635/Python-or-Simple-solution-or-O(-n-)-Time-Complexity. | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
lessPivot = []
GreaterPivot = []
k = 0
for num in nums:
if num < pivot:
lessPivot.insert(k, num) # Element less than pivot inserted at f... | partition-array-according-to-given-pivot | Python | Simple solution | O( n ) Time Complexity. | devshailesh | 0 | 62 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,031 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2626029/One-Liner-or-Python-Super-Easy | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return [i for i in nums if i<pivot]+[i for i in nums if i==pivot]+[i for i in nums if i>pivot] | partition-array-according-to-given-pivot | One Liner | Python Super Easy | RajatGanguly | 0 | 14 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,032 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2535109/Python-or-Array-or-O(n)-Time-or-O(n)-Space | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less, equal, greater = [], [], []
for num in nums:
if num<pivot:
less.append(num)
elif num>pivot:
greater.append(num)
else:
equ... | partition-array-according-to-given-pivot | Python | Array | O(n) Time | O(n) Space | coolakash10 | 0 | 32 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,033 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2513615/Easy-Python-solution-using-Arrays | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less=[]
Pivot=[]
greater=[]
for i in nums:
if i<pivot:
less.append(i)
elif i==pivot:
Pivot.append(i)
else:
greater.append(i)
ans=less+Pivot+greater
return ans | partition-array-according-to-given-pivot | Easy Python solution using Arrays | keertika27 | 0 | 26 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,034 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2411141/Simple-python-code-with-explanation | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
#create a less-->list to store the values less than pivot
less = []
#create a pivotval-->list to store the values equal to pivot
pivotval = []
#create a... | partition-array-according-to-given-pivot | Simple python code with explanation | thomanani | 0 | 31 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,035 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2336521/Python-easy-beginner-solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
smol = []
bhig = []
same = []
for i in nums:
if i < pivot:
smol.append(i)
elif i > pivot:
bhig.append(i)
elif i == pivot:
... | partition-array-according-to-given-pivot | Python easy beginner solution | EbrahimMG | 0 | 51 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,036 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/2298004/Python-really-easy-to-understand-solution.-O(n) | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
lst=[]
for i in nums:
if i<pivot:
lst.append(i)
for i in nums:
if i==pivot:
lst.append(i)
for i in nums:
if i>pivot:
lst... | partition-array-according-to-given-pivot | Python really easy to understand solution. O(n) | guneet100 | 0 | 54 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,037 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1989938/Simple-Python-Solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
pos=0
ans=[-1]*len(nums)
for i in range(len(nums)):
if nums[i] != 'v' and nums[i]<pivot:
ans[pos]=nums[i]
pos+=1
nums[i]='v'
for i in range(len(... | partition-array-according-to-given-pivot | Simple Python Solution | Siddharth_singh | 0 | 62 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,038 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1939603/Python3-Simple-Solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
left = []
mid = []
right = []
for n in nums:
if n < pivot:
left.append(n)
elif n == pivot:
mid.append(n)
elif n > pivot:
... | partition-array-according-to-given-pivot | [Python3] Simple Solution | terrencetang | 0 | 83 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,039 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1918533/WEEB-DOES-PYTHONC%2B%2B | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
left, mid, right = [], [], []
for i in range(len(nums)):
if nums[i] < pivot:
left.append(nums[i])
elif nums[i] > pivot:
right.append(nums[i])
else:
mid.append(nums[i])
return left + mid + right | partition-array-according-to-given-pivot | WEEB DOES PYTHON/C++ | Skywalker5423 | 0 | 42 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,040 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1867107/Python-solution-easy-for-beginners | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
piv = []
low = []
high = []
for i in nums:
if i == pivot:
piv.append(i)
elif i < pivot:
low.append(i)
else:
high.append(... | partition-array-according-to-given-pivot | Python solution, easy for beginners | alishak1999 | 0 | 57 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,041 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1789402/Simple-solution-faster-than-99.7 | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
small_list = [item for item in nums if item < pivot]
large_list = [item for item in nums if item > pivot]
pivot_count = nums.count(pivot)
return small_list + [pivot]*pivot_count + large_list | partition-array-according-to-given-pivot | Simple solution faster than 99.7% | blackmishra | 0 | 91 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,042 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1787624/Simple-Python-solution-(n-log-n) | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
def key(v):
if v < pivot:
return -1
if v > pivot:
return 1
return 0
return sorted(nums, key=key) | partition-array-according-to-given-pivot | Simple Python solution, (n log n) | emwalker | 0 | 83 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,043 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1787288/Python3-one-liner | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return ([x for x in nums if x < pivot] + [x for x in nums if x == pivot] + [x for x in nums if x > pivot]) | partition-array-according-to-given-pivot | Python3 one-liner | rrrares | 0 | 41 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,044 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1774450/Simple-and-faster-than-99.67 | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
les = []
great = []
for item in nums:
if item < pivot:
les.append(item)
elif item > pivot:
great.append(item)
return les+nums.count(pivot)*[pivot] +... | partition-array-according-to-given-pivot | Simple and faster than 99.67% | blackmishra | 0 | 29 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,045 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1762927/Python3-simple-solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
left = []
equal = []
right = []
i = 0
while i < len(nums):
if nums[i] < pivot:
left.append(nums[i])
elif nums[i] == pivot:
equal.append(nums... | partition-array-according-to-given-pivot | Python3 simple solution | EklavyaJoshi | 0 | 33 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,046 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1748055/Python3-3-parts | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
small, equal, large = [], [], []
for x in nums:
if x < pivot: small.append(x)
elif x == pivot: equal.append(x)
else: large.append(x)
return small + equal + large | partition-array-according-to-given-pivot | [Python3] 3 parts | ye15 | 0 | 30 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,047 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1747411/Easy-solution-JavaScript-and-Python3 | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
l,e,g = [], [], []
for item in nums :
if item == pivot :
e.append(item)
if item < pivot :
l.append(item)
if item > pivot :... | partition-array-according-to-given-pivot | Easy solution - JavaScript & Python3 | shakilbabu | 0 | 25 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,048 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1747136/Python3-Solution | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less = []
equal = []
greater = []
for i in range(len(nums)):
if nums[i]<pivot:
less.append(nums[i])
elif nums[i]==pivot:
equal.append(nums[i])
... | partition-array-according-to-given-pivot | Python3 Solution | light_1 | 0 | 25 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,049 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1747065/Easy-Python-Solutions%3A-3-List-and-1-list | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
# get all less than pivot elements
less_than = [i for i in nums if i < pivot]
# get all pivot elements
eq = [i for i in nums if i == pivot]
# get all greater than pivot elements
greater_than = [i f... | partition-array-according-to-given-pivot | Easy Python Solutions: 3 List and 1 list | theanilbajar | 0 | 26 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,050 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1747065/Easy-Python-Solutions%3A-3-List-and-1-list | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
n = len(nums)
res = [0]*(n)
less_index = 0
pivot_start_index = 0
greater_start_index = n
# update start indices to add pivot and greater than pivot elements
... | partition-array-according-to-given-pivot | Easy Python Solutions: 3 List and 1 list | theanilbajar | 0 | 26 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,051 |
https://leetcode.com/problems/partition-array-according-to-given-pivot/discuss/1747037/Easy-Python3-Solution-Brute-Force | class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
lessthan = []
for i in nums:
if i < pivot:
lessthan.append(i)
equal = []
for i in nums:
if i == pivot:
equal.append(i)
great = []
fo... | partition-array-according-to-given-pivot | Easy Python3 Solution Brute Force | sdasstriver9 | 0 | 34 | partition array according to given pivot | 2,161 | 0.845 | Medium | 30,052 |
https://leetcode.com/problems/minimum-cost-to-set-cooking-time/discuss/1746996/Simple-Python-Solution | class Solution:
def minCostSetTime(self, startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
def count_cost(minutes, seconds): # Calculates cost for certain configuration of minutes and seconds
time = f'{minutes // 10}{minutes % 10}{seconds // 10}{seconds % 10}' # mm:ss
... | minimum-cost-to-set-cooking-time | Simple Python Solution | anCoderr | 10 | 513 | minimum cost to set cooking time | 2,162 | 0.396 | Medium | 30,053 |
https://leetcode.com/problems/minimum-cost-to-set-cooking-time/discuss/1758788/Cooking-time-as-string-80-speed | class Solution:
def minCostSetTime(self, startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
start_c, min_cost = str(startAt), inf
def cost(t: str) -> int:
return (pushCost * len(t) + moveCost *
sum(a != b for a, b in zip(start_c + t, t)))
... | minimum-cost-to-set-cooking-time | Cooking time as string, 80% speed | EvgenySH | 0 | 65 | minimum cost to set cooking time | 2,162 | 0.396 | Medium | 30,054 |
https://leetcode.com/problems/minimum-cost-to-set-cooking-time/discuss/1748828/python-solution-faster-than-87.5 | class Solution:
def minCostSetTime(self, startAt: int, moveCost: int, pushCost: int, t: int) -> int:
res = []
minu,min_sec = divmod(t,60)
if minu <= 99:
res.append([minu,min_sec])
if min_sec + 60 <= 99 and minu -1 >= 0:
res.append([minu-1,min_sec + 60])
... | minimum-cost-to-set-cooking-time | python solution faster than 87.5% | biancai3939 | 0 | 28 | minimum cost to set cooking time | 2,162 | 0.396 | Medium | 30,055 |
https://leetcode.com/problems/minimum-cost-to-set-cooking-time/discuss/1747280/Python3-simulation | class Solution:
def minCostSetTime(self, startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
m, s = divmod(targetSeconds, 60)
cands = []
if m < 100: cands.append((str(m) + str(s).zfill(2)).lstrip('0'))
if m and s+60 < 100: cands.append((str(m-1) + str(s+60).zfill(... | minimum-cost-to-set-cooking-time | [Python3] simulation | ye15 | 0 | 29 | minimum cost to set cooking time | 2,162 | 0.396 | Medium | 30,056 |
https://leetcode.com/problems/minimum-cost-to-set-cooking-time/discuss/1747226/Python-simple-solution | class Solution:
def minCostSetTime(self, startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
mins1,secs1 = (0,targetSeconds) if targetSeconds<100 else (targetSeconds//60,targetSeconds%60)
if mins1>99:
mins1 -= 1
secs1 += 60
l = [(mins1,secs1)]
... | minimum-cost-to-set-cooking-time | Python simple solution | 1579901970cg | 0 | 25 | minimum cost to set cooking time | 2,162 | 0.396 | Medium | 30,057 |
https://leetcode.com/problems/minimum-cost-to-set-cooking-time/discuss/1747185/Python-O(1)-solution | class Solution:
def minCostSetTime(self, startAt: int, moveCost: int, pushCost: int, targetSeconds: int) -> int:
mins = targetSeconds // 60
secs = targetSeconds % 60
min_cost = math.inf
if mins <= 99:
cost1 = cost(mins, secs, startAt, moveCost, pushCost)
... | minimum-cost-to-set-cooking-time | [Python] O(1) solution | mostafaa | 0 | 36 | minimum cost to set cooking time | 2,162 | 0.396 | Medium | 30,058 |
https://leetcode.com/problems/minimum-difference-in-sums-after-removal-of-elements/discuss/2392142/Python-solution-or-O(nlogn)-or-explained-with-diagram-or-heap-and-dp-solution | class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums) // 3
# calculate max_sum using min_heap for second part
min_heap = nums[(2 * n) :]
heapq.heapify(min_heap)
max_sum = [0] * (n + 2)
max_sum[n + 1] = sum(min_heap)
for i in rang... | minimum-difference-in-sums-after-removal-of-elements | Python solution | O(nlogn) | explained with diagram | heap and dp solution | wilspi | 1 | 64 | minimum difference in sums after removal of elements | 2,163 | 0.467 | Hard | 30,059 |
https://leetcode.com/problems/minimum-difference-in-sums-after-removal-of-elements/discuss/1747399/Python-3-SortedList-solution-time-O(NlogN)-space-O(N)-equivalent-to-2-heaps | class Solution:
def minimumDifference(self, nums: List[int]) -> int:
# Python solution using SortedList, time complexity O(nlogn), space complexity O(n)
n = len(nums) // 3
from sortedcontainers import SortedList
leftArr = SortedList(nums[ : n])
rightArr = SortedList(nums[n... | minimum-difference-in-sums-after-removal-of-elements | Python 3 SortedList solution, time O(NlogN) space O(N), equivalent to 2 heaps | xil899 | 1 | 54 | minimum difference in sums after removal of elements | 2,163 | 0.467 | Hard | 30,060 |
https://leetcode.com/problems/minimum-difference-in-sums-after-removal-of-elements/discuss/1748061/Python3-priority-queue | class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums)//3
pq0 = [-x for x in nums[:n]]
pq1 = nums[-n:]
heapify(pq0)
heapify(pq1)
ans = -sum(pq0) - sum(pq1)
prefix = [0]
for i in range(n, 2*n):
... | minimum-difference-in-sums-after-removal-of-elements | [Python3] priority queue | ye15 | 0 | 30 | minimum difference in sums after removal of elements | 2,163 | 0.467 | Hard | 30,061 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2214566/Python-oror-In-Place-Sorting | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
n = len(nums)
for i in range(0,n,2):
for j in range(i+2,n,2):
if nums[i] > nums[j]:
nums[i],nums[j] = nums[j], nums[i]
for i in range(1,n,2):
for j in range(i+2,n,2):
if nums[i] < nums[j]:
nums[i],nums[j] = nums[j], num... | sort-even-and-odd-indices-independently | Python || In Place Sorting | morpheusdurden | 1 | 186 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,062 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1748459/Python-or-Easy-Solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
even_list = []
odd_list = []
for i in range(len(nums)):
if((i%2)==0):
even_list.append(nums[i])
else:
odd_list.append(nums[i])
even_list = sorted(even_list)
... | sort-even-and-odd-indices-independently | 👨💻 ✔Python | Easy Solution ✔👨💻 | DaemonStark | 1 | 90 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,063 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2782963/Best-Easy-Solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
lst=[]
dst=[]
bst=[]
mst=[]
cst=[0]*len(nums)
for i in range(len(nums)):
if i%2==0:
lst.append(nums[i])
dst.append(i)
else:
bst... | sort-even-and-odd-indices-independently | Best Easy Solution | Kaustubhmishra | 0 | 7 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,064 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2782962/Best-Easy-Solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
lst=[]
dst=[]
bst=[]
mst=[]
cst=[0]*len(nums)
for i in range(len(nums)):
if i%2==0:
lst.append(nums[i])
dst.append(i)
else:
bst... | sort-even-and-odd-indices-independently | Best Easy Solution | Kaustubhmishra | 0 | 3 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,065 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2776742/Simple-Python-or-Two-liner | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
nums[0::2], nums[1::2] = sorted(nums[::2]), sorted(nums[1::2])[::-1]
return nums | sort-even-and-odd-indices-independently | Simple Python | Two liner | blindspot_vikram | 0 | 4 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,066 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2690531/Easy-and-optimal-one-line-code | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
nums[::2],nums[1::2]=sorted(nums[::2]),sorted(nums[1::2])[::-1]
return nums | sort-even-and-odd-indices-independently | Easy and optimal one line code | Raghunath_Reddy | 0 | 10 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,067 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2572870/Python3-Counting-sort%3A-O(n)-constant-space%3A-O(1) | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
self.evencount(nums)
self.oddcount(nums)
return nums
def evencount(self, arr: List[int]) -> List[int]:
valToFre = [0] * 101
for i in range(0, len(arr), 2):
valToFre[arr[i]] += 1
... | sort-even-and-odd-indices-independently | [Python3] Counting sort: O(n), constant space: O(1) | DG_stamper | 0 | 32 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,068 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2186234/Python-simple-solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
x = sorted([nums[x] for x in range(0, len(nums), 2)])
y = sorted([nums[y] for y in range(1, len(nums), 2)], reverse=True)
z = []
for i in range(len(nums)//2+1):
if i < len(x):
z.append(x[... | sort-even-and-odd-indices-independently | Python simple solution | StikS32 | 0 | 97 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,069 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2036168/Python-Clear-and-Concise-3-Lines! | class Solution:
def sortEvenOdd(self, nums):
evenNums = deque(sorted([nums for i,nums in enumerate(nums) if i % 2 == 0]))
oddNums = deque(sorted([nums for i,nums in enumerate(nums) if i % 2 == 1], reverse=True))
return [evenNums.popleft() if i % 2 == 0 else oddNums.popleft() for i in range(... | sort-even-and-odd-indices-independently | Python - Clear and Concise [3 Lines]! | domthedeveloper | 0 | 99 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,070 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1980541/Python-(Simple-Approach-and-Beginner-Friendly) | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
if len(nums) <= 2: return nums
odd = []
even = []
for i in range(0, len(nums), 2):
even.append(nums[i])
for i in range(1, len(nums), 2):
odd.append(nums[i])
odd.sort(reverse =... | sort-even-and-odd-indices-independently | Python (Simple Approach and Beginner-Friendly) | vishvavariya | 0 | 73 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,071 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1841455/Python3-Faster-Than-99.06-Easy-Understand | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
odd, even = [], []
for i in range(len(nums)):
if i % 2 == 0:
even.append(nums[i])
else:
odd.append(nums[i])
y, x = sorted(odd, reverse = True), sorted(even)
... | sort-even-and-odd-indices-independently | Python3, Faster Than 99.06%, Easy Understand | Hejita | 0 | 70 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,072 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1800801/Python3-accepted-solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
even = []; odd = []; ans =[]
for i in range(len(nums)):
if(i%2==0):
even.append(nums[i])
else: odd.append(nums[i])
even.sort()
odd.sort(reverse=True)
for i in range(le... | sort-even-and-odd-indices-independently | Python3 accepted solution | sreeleetcode19 | 0 | 61 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,073 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1752572/Python3-simple-solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
even = []
odd = []
if len(nums) < 3:
return nums
for i in range(len(nums)):
if i % 2 == 0:
even.append(nums[i])
else:
odd.append(... | sort-even-and-odd-indices-independently | Python3 simple solution | noobj097 | 0 | 32 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,074 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1751805/pythonic-by-slicing | class Solution:
def sortEvenOdd(self, nums):
return self.pythonic(nums)
def pythonic(self, nums):
nums[::2], nums[1::2] = sorted(nums[::2]), sorted(nums[1::2], reverse=True)
return nums | sort-even-and-odd-indices-independently | pythonic, by slicing | steve-jokes | 0 | 64 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,075 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1751021/Python-3-counting-sort-O(n)-O(n) | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
odd_count = collections.defaultdict(lambda: 0)
even_count = collections.defaultdict(lambda: 0)
for i, num in enumerate(nums):
if i % 2:
odd_count[num] += 1
else:
... | sort-even-and-odd-indices-independently | Python 3, counting sort, O(n) / O(n) | dereky4 | 0 | 81 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,076 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1750494/Python-Easy-Readable-Solution | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
even_list = []
odd_list = []
for i,c in enumerate(nums):
if i%2 == 0:
even_list.append(c)
else:
odd_list.append(c)
even_list = sorted(even_list,reverse=True)
... | sort-even-and-odd-indices-independently | [Python] Easy, Readable Solution | user9454R | 0 | 50 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,077 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1749107/Intuitive-approach-by-using-list-index-%3A%3A2 | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
nums[::2] = sorted(nums[::2])
nums[1::2] = sorted(nums[1::2], reverse=True)
return nums | sort-even-and-odd-indices-independently | Intuitive approach by using list index [::2] | puremonkey2001 | 0 | 14 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,078 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1748633/Python-Simple-and-Clean-Python-by-Separating-Even-and-Odd-index-in-two-arrays | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
arr_even=[]
arr_odd=[]
for i in range(len(nums)):
if i%2==0:
arr_even.append(nums[i])
else:
arr_odd.append(nums[i])
arr_even=sorted(arr_even)
arr_odd=sorted(arr_odd)[::-1]
ans=[]
l=min(len(arr_even),len(arr_odd))
for... | sort-even-and-odd-indices-independently | [ Python ] ✔✔ Simple and Clean Python by Separating Even and Odd index in two arrays | ASHOK_KUMAR_MEGHVANSHI | 0 | 75 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,079 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1748558/Self-understandable-Python-%3A | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
a=[]
b=[]
for i in range(len(nums)):
if i%2==0:
a.append(nums[i])
else:
b.append(nums[i])
a.sort()
b=sorted(b,reverse=True)
c=0
d=0
... | sort-even-and-odd-indices-independently | Self understandable Python : | goxy_coder | 0 | 60 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,080 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2298627/Python-1-Liner-with-explanation | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
return [num for num in chain.from_iterable(itertools.zip_longest(sorted(nums[::2]), sorted(nums[1::2], reverse=True))) if num is not None] | sort-even-and-odd-indices-independently | Python 1-Liner with explanation | amaargiru | -1 | 78 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,081 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/2298627/Python-1-Liner-with-explanation | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
evens = sorted(nums[::2])
odds = sorted(nums[1::2], reverse=True)
# 🠓 Made flat zip(), see stackoverflow.com/questions/61943924/python-flat-zip
total = [num for num in chain.from_iterable(iter... | sort-even-and-odd-indices-independently | Python 1-Liner with explanation | amaargiru | -1 | 78 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,082 |
https://leetcode.com/problems/sort-even-and-odd-indices-independently/discuss/1807620/1-Line-Python-Solution-oror-92-Faster-oror-Memory-less-than-80 | class Solution:
def sortEvenOdd(self, nums: List[int]) -> List[int]:
return reduce(add, zip_longest(sorted([nums[i] for i in range(0,len(nums),2)]), sorted([nums[i] for i in range(1,len(nums),2)])[::-1]))[:len(nums)] | sort-even-and-odd-indices-independently | 1-Line Python Solution || 92% Faster || Memory less than 80% | Taha-C | -1 | 121 | sort even and odd indices independently | 2,164 | 0.664 | Easy | 30,083 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/1755847/PYTHON3-or-EASY-SOLUTION-or | class Solution:
def smallestNumber(self, num: int) -> int:
if num == 0 : return 0
snum = sorted(str(num))
if snum[0] == '-' :
return -int("".join(snum[:0:-1]))
elif snum[0] == '0' :
x = snum.count('0')
return "".join([snum[x]]+['0'*x]+snu... | smallest-value-of-the-rearranged-number | PYTHON3 | EASY SOLUTION | | rohitkhairnar | 1 | 108 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,084 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/1748482/Easy-Python | class Solution:
def smallestNumber(self, num: int) -> int:
if num==0:
return 0
if num>=0:
num=str(num)
num=sorted(num)
ans=''
z=num.count('0')
for i in range(z):
num.pop(0)
if len(num)>0:
... | smallest-value-of-the-rearranged-number | Easy Python | ro_hit2013 | 1 | 64 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,085 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/2540010/use-SORTING-cleaver-solution-O(n-logn)-beats-98.86 | class Solution:
def smallestNumber(self, num: int) -> int:
if num ==0 : return 0
res , zero = '',''
for i in str(num):
if i != '-':
if i=='0':
zero += i
else:
res += i
res = ''.join(... | smallest-value-of-the-rearranged-number | use SORTING cleaver solution O(n logn) [beats 98.86%] | _jorjis | 0 | 48 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,086 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/2473513/Python-Without-String-and-with-NumberSort-O(N) | class Solution:
def smallestNumber(self, num: int) -> int:
# no digits contained, can return zero
if not num:
return 0
# make an array to count the digits
digits = [0]*10
# check whether number is negative
negative = num < 0
... | smallest-value-of-the-rearranged-number | [Python] Without String and with NumberSort - O(N) | Lucew | 0 | 25 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,087 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/2271241/Python-Easy | class Solution:
def smallestNumber(self, num: int) -> int:
isnegative = True if num<0 else False
nums = str(num)
if isnegative:
nums = [(ch) for ch in nums[1:]]
nums.sort(reverse = True)
return -int(''.join(nums))
if not isnegative:
num... | smallest-value-of-the-rearranged-number | Python Easy | Abhi_009 | 0 | 16 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,088 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/2214584/Python-oror-Simple | class Solution:
def smallestNumber(self, num: int) -> int:
num = str(num)
n = len(num)
if n <= 1: return num
if int(num) < 0:
num = sorted(num, reverse = True)
sign = -1
else:
sign = 1
num = sorted(num)
i = 0
while i < n and num[i] == '0': i+= 1
num = [num[i]] + num[:i] + num[i+1:]
i... | smallest-value-of-the-rearranged-number | Python || Simple | morpheusdurden | 0 | 21 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,089 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/1838797/python-sorting-or-swapping-or-string | class Solution:
def smallestNumber(self, num: int) -> int:
sign = 1 if num >= 0 else -1
temp = None
if sign == 1:
temp = sorted(str(num))
else:
temp = sorted(str(num)[1:], reverse = True)
if temp[0] == '0':
i = 0
... | smallest-value-of-the-rearranged-number | python sorting | swapping | string | abkc1221 | 0 | 82 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,090 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/1791856/Python3-accepted-solution-(using-lstrip) | class Solution:
def smallestNumber(self, num: int) -> int:
if(num==0):return 0
if(num>0):
s = "".join(sorted(str(num)))
return(int(s.lstrip("0")[0] + "0"*(len(s)-(len(s.lstrip("0")))) + s.lstrip("0")[1:]))
if(num<0):
num = (-1)*num
return(int("... | smallest-value-of-the-rearranged-number | Python3 accepted solution (using lstrip) | sreeleetcode19 | 0 | 27 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,091 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/1761450/Easy-Brute-Force-Solution-for-Beginners-!!!-82-Faster | class Solution:
def smallestNumber(self, num: int) -> int:
if num==0:
return 0
if num>0:
num=str(num)
li_num=[]
for i in num:
li_num.append(int(i))
li_num.sort()
if li_num[0]==0:
for j in range(1,... | smallest-value-of-the-rearranged-number | Easy Brute Force Solution for Beginners !!! 82% Faster | pratiyush_ray | 0 | 60 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,092 |
https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/1748520/Self-Understandable-Python-%3A | class Solution:
def smallestNumber(self, num: int) -> int:
if num//10==0:
return num
if num<0:
sign=-1
else:
sign=1
num=abs(num)
if sign==-1:
s=sorted(str(num),reverse=True)
return sign*int("".join(s))
el... | smallest-value-of-the-rearranged-number | Self Understandable Python : | goxy_coder | 0 | 37 | smallest value of the rearranged number | 2,165 | 0.513 | Medium | 30,093 |
https://leetcode.com/problems/minimum-time-to-remove-all-cars-containing-illegal-goods/discuss/2465604/Python3-dp | class Solution:
def minimumTime(self, s: str) -> int:
ans = inf
prefix = 0
for i, ch in enumerate(s):
if ch == '1': prefix = min(2 + prefix, i+1)
ans = min(ans, prefix + len(s)-1-i)
return ans | minimum-time-to-remove-all-cars-containing-illegal-goods | [Python3] dp | ye15 | 0 | 24 | minimum time to remove all cars containing illegal goods | 2,167 | 0.402 | Hard | 30,094 |
https://leetcode.com/problems/minimum-time-to-remove-all-cars-containing-illegal-goods/discuss/1768795/Python-or-prefix_sum-or-easy-to-understand | class Solution:
def minimumTime(self, s: str) -> int:
costL2R = [None]*len(s)
cost = 0 if s[0]=='0' else 1
costL2R[0]=cost
for i in range(1,len(s)):
if s[i]=='1':
cost = min(cost+2,i+1)
costL2R[i]=cost
costR2... | minimum-time-to-remove-all-cars-containing-illegal-goods | Python | prefix_sum | easy to understand | albertnew2018 | 0 | 84 | minimum time to remove all cars containing illegal goods | 2,167 | 0.402 | Hard | 30,095 |
https://leetcode.com/problems/count-operations-to-obtain-zero/discuss/1766882/Python3-simulation | class Solution:
def countOperations(self, num1: int, num2: int) -> int:
ans = 0
while num1 and num2:
ans += num1//num2
num1, num2 = num2, num1%num2
return ans | count-operations-to-obtain-zero | [Python3] simulation | ye15 | 4 | 385 | count operations to obtain zero | 2,169 | 0.755 | Easy | 30,096 |
https://leetcode.com/problems/count-operations-to-obtain-zero/discuss/1768763/Python3-or-2-approaches-Normal-and-Optimized-in-time | class Solution:
def countOperations(self, num1: int, num2: int) -> int:
ct=0
while num2 and num1:
if num1>=num2:
num1=num1-num2
else:
num2=num2-num1
ct+=1
return ct | count-operations-to-obtain-zero | Python3 | 2 approaches Normal and Optimized in time | Anilchouhan181 | 3 | 273 | count operations to obtain zero | 2,169 | 0.755 | Easy | 30,097 |
https://leetcode.com/problems/count-operations-to-obtain-zero/discuss/1768763/Python3-or-2-approaches-Normal-and-Optimized-in-time | class Solution:
def countOperations(self, num1: int, num2: int) -> int:
ans = 0
if num1 < num2:
num1, num2 = num2, num1
while num2:
num1, num2 = num2, num1 - num2
if num1 < num2:
num1, num2 = num2, num1
ans += 1
return a... | count-operations-to-obtain-zero | Python3 | 2 approaches Normal and Optimized in time | Anilchouhan181 | 3 | 273 | count operations to obtain zero | 2,169 | 0.755 | Easy | 30,098 |
https://leetcode.com/problems/count-operations-to-obtain-zero/discuss/2731626/PythonororO(N) | class Solution:
def countOperations(self, num1: int, num2: int) -> int:
count=0
while num1!=0 and num2!=0:
if num1>num2:
num1=num1-num2
count+=1
else:
num2=num2-num1
count+=1
return count | count-operations-to-obtain-zero | Python||O(N) | Sneh713 | 1 | 99 | count operations to obtain zero | 2,169 | 0.755 | Easy | 30,099 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.