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/decompress-run-length-encoded-list/discuss/2713811/recursive-solution-or-Python-3
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: freq = 0 val = 1 newArr = [] if len(nums) != 0: newArr += nums[freq] * [nums[val]] else: return newArr return newArr + self.decompressRLElist(nums[val+1:])
decompress-run-length-encoded-list
recursive solution | Python 3
mr6nie
0
2
decompress run length encoded list
1,313
0.859
Easy
19,600
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2705907/Python-best-Solution
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: res =[] for i in range(0,len(nums),2): res+=([nums[i+1]]*nums[i]) return res
decompress-run-length-encoded-list
Python best Solution
kartik_5051
0
3
decompress run length encoded list
1,313
0.859
Easy
19,601
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2669590/one-line-Python
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: return list(itertools.chain.from_iterable([nums[2 * i + 1]] * nums[i * 2] for i in range(len(nums) // 2)))
decompress-run-length-encoded-list
one line Python
MaryLuz
0
2
decompress run length encoded list
1,313
0.859
Easy
19,602
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2668124/Explained-efficient-Python-solution-utilizing-Generators
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: """ Straightforward basic solution Try to optimize via moving to generators """ # i = 0 # res = [] # while i < len(nums): # freq = nums[i] # val = nums[i+1] ...
decompress-run-length-encoded-list
Explained, efficient Python solution utilizing Generators
NGUgeneral
0
1
decompress run length encoded list
1,313
0.859
Easy
19,603
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2664570/Simple-python-code-with-explanation
class Solution: def decompressRLElist(self, nums): #create a empty list(freq) to store frequency which is at even indexes freq = [] #create a empty list(val) to store value which is at odd indexes val = [] #iterate over the elements in list(nums) for i in range(len(nu...
decompress-run-length-encoded-list
Simple python code with explanation
thomanani
0
13
decompress run length encoded list
1,313
0.859
Easy
19,604
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2611099/72-ms-faster-than-89.56-of-Python3
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: res = [] for i in range(len(nums)//2): res+=[nums[2*i+1] for j in range(nums[2*i])] return res
decompress-run-length-encoded-list
72 ms, faster than 89.56% of Python3
Abdulahad_Abduqahhorov
0
20
decompress run length encoded list
1,313
0.859
Easy
19,605
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2530222/Python-Solution-easy-and-fast
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: res = [] l = len(nums) for i in range(0,l,2): for j in range(nums[i]): res.append(nums[i+1]) return res
decompress-run-length-encoded-list
Python Solution easy and fast
savvy_phukan
0
49
decompress run length encoded list
1,313
0.859
Easy
19,606
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2508908/Python-or-2-easy-to-read-solutions
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: res = [] i = 0 while(i < len(nums)): for _ in range(nums[i]): res.append(nums[i+1]) i += 2 return res
decompress-run-length-encoded-list
Python | 2 easy to read solutions
Wartem
0
50
decompress run length encoded list
1,313
0.859
Easy
19,607
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2508908/Python-or-2-easy-to-read-solutions
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: freq = nums[::2] val = nums[1::2] res = [] for i in range(len(freq)): for _ in range(freq[i]): res.append(val[i]) return res
decompress-run-length-encoded-list
Python | 2 easy to read solutions
Wartem
0
50
decompress run length encoded list
1,313
0.859
Easy
19,608
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2439954/1313.-Decompress-Run-Length-Encoded-List%3A-1-Liner
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: return [nums[index] for index,element in enumerate(nums) if index%2!=0 for x in range(nums[index-1])]
decompress-run-length-encoded-list
1313. Decompress Run-Length Encoded List: 1 Liner
rogerfvieira
0
12
decompress run length encoded list
1,313
0.859
Easy
19,609
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2421878/easiest-python-solution
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: res=[] for i in range(1,len(nums),2): for j in range(nums[i-1]): res.append(nums[i]) return res
decompress-run-length-encoded-list
easiest python solution
Abdulrahman_Ahmed
0
34
decompress run length encoded list
1,313
0.859
Easy
19,610
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2382225/Python3-solution-O(N2)-time-complexity-O(N)-space-complexity-90-faster
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: answer = [] for i in range(0, len(nums), 2): for j in range(0, nums[i]): answer.append(nums[i + 1]) return answer
decompress-run-length-encoded-list
Python3 solution, O(N^2) time complexity, O(N) space complexity, 90% faster
matteogianferrari
0
33
decompress run length encoded list
1,313
0.859
Easy
19,611
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2249142/Easy-to-Understand-Python-3-solution....-faster-than-98
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: lst=[] for i in range(0,len(nums),2): lst.extend(nums[i]*[nums[i+1]]) return lst
decompress-run-length-encoded-list
Easy to Understand Python 3 solution.... faster than 98%
guneet100
0
67
decompress run length encoded list
1,313
0.859
Easy
19,612
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2050646/1-loop-solution-(Python3)
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: array = [] for i in range(1, len(nums), 2): array += nums[i-1] * [nums[i]] return array ```
decompress-run-length-encoded-list
1 loop solution (Python3)
Encelad
0
47
decompress run length encoded list
1,313
0.859
Easy
19,613
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2035203/Python3-simple-code
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: i = 0; decompressed = [] for _ in nums: if i < len(nums): for _ in range(nums[i]): decompressed.append(nums[i + 1]) i += 2 return decompressed
decompress-run-length-encoded-list
[Python3] simple code
Shiyinq
0
30
decompress run length encoded list
1,313
0.859
Easy
19,614
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1927914/Faster-than-95-Python-Solution-6-Lines
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: arr = [] for i in range(1,len(nums),2): l = nums[i-1:i+1] for j in range(0,l[0]): arr.append(l[1]) return arr
decompress-run-length-encoded-list
Faster than 95% Python Solution 6 Lines
itsmeparag14
0
35
decompress run length encoded list
1,313
0.859
Easy
19,615
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1869681/My-easy-to-understand-Python-submission.
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: i,j=0,1 ans=[] while j<len(nums): temp=[nums[j]]*nums[i] ans+=temp i+=2 j+=2 return ans
decompress-run-length-encoded-list
My easy to understand Python submission.
tkdhimanshusingh
0
63
decompress run length encoded list
1,313
0.859
Easy
19,616
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1866587/Python-(Simple-Approach-and-Beginner-Friendly)
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: arr = [] for i in range(1, len(nums), 2): for j in range(nums[i-1]): arr.append(nums[i]) return arr
decompress-run-length-encoded-list
Python (Simple Approach and Beginner-Friendly)
vishvavariya
0
26
decompress run length encoded list
1,313
0.859
Easy
19,617
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1863245/Python-solution-faster-than-86
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: res = [] for i in range(len(nums)-1): if i % 2 == 0: res.extend([nums[i+1]]*nums[i]) return res
decompress-run-length-encoded-list
Python solution faster than 86%
alishak1999
0
33
decompress run length encoded list
1,313
0.859
Easy
19,618
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1855502/Python-3-solution
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: n = 2 ans = [] for i in [nums[num:num+n] for num in range(0, len(nums), n)]: freq, val = i[0], i[1] ans += [val] * freq return ans
decompress-run-length-encoded-list
Python 3 solution
zuzannakilar
0
23
decompress run length encoded list
1,313
0.859
Easy
19,619
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1812962/3-Lines-Python-Solution-oror-60-Faster-oror-Memory-less-than-92
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: ans = [] for i in range(0,len(nums),2): ans += [nums[i+1]]*nums[i] return ans
decompress-run-length-encoded-list
3-Lines Python Solution || 60% Faster || Memory less than 92%
Taha-C
0
46
decompress run length encoded list
1,313
0.859
Easy
19,620
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1730044/Python-dollarolution
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: v = [] for i in range(0,len(nums),2): for _ in range(nums[i]): v.append(nums[i+1]) return v
decompress-run-length-encoded-list
Python $olution
AakRay
0
83
decompress run length encoded list
1,313
0.859
Easy
19,621
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1723145/Decompress-Run-Length-Encoded-List-Python-Solution
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: flst=[] j=0 lst=[] for i in range(1,len(nums),2): lst.append([nums[i]]*nums[j]) j+=2 for x in lst: for y in x: flst.append(y) return flst
decompress-run-length-encoded-list
Decompress Run-Length Encoded List Python Solution
seabreeze
0
16
decompress run length encoded list
1,313
0.859
Easy
19,622
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1691802/2-Methods-or-Python3
class Solution: def decompressRLElist(self, nums): i = 0 res = [] while i<len(nums): res+=([nums[i+1]]*nums[i]) i+=2 return res
decompress-run-length-encoded-list
2 Methods | Python3 🐍
hritik5102
0
88
decompress run length encoded list
1,313
0.859
Easy
19,623
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1691802/2-Methods-or-Python3
class Solution: def decompressRLElist(self, nums): return [res for i in range(0,len(nums),2) for res in [nums[i+1]]*nums[i]] obj = Solution() print(obj.decompressRLElist([1,2,3,4]))
decompress-run-length-encoded-list
2 Methods | Python3 🐍
hritik5102
0
88
decompress run length encoded list
1,313
0.859
Easy
19,624
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1632649/Python-Easy-Solution-Using-While-loop
class Solution(object): def decompressRLElist(self, nums): i=0 l=[] while(i<len(nums)): for j in range(nums[i]): l.append(nums[i+1]) i+=2 return l
decompress-run-length-encoded-list
Python Easy Solution Using While loop
Manasa_Alapaka
0
38
decompress run length encoded list
1,313
0.859
Easy
19,625
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1383067/Barely-2-line-solution-in-Python
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: from itertools import chain return list(chain.from_iterable((val for _ in range(freq)) for freq, val in zip(nums[::2], nums[1::2])))
decompress-run-length-encoded-list
Barely 2-line solution in Python
mousun224
0
84
decompress run length encoded list
1,313
0.859
Easy
19,626
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1281389/Python-Runtime%3A-60-ms-faster-than-92.69-.
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: ans = [] for i in range(0, len(nums), 2): ans.extend([nums[i + 1]] * nums[i]) return ans
decompress-run-length-encoded-list
Python Runtime: 60 ms, faster than 92.69% .
aditi_shree
0
128
decompress run length encoded list
1,313
0.859
Easy
19,627
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1223818/Python-Solution-(76.47)-oror-please-suggest-optimization
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: arr = [] for i in range(0, len(nums), 2): arr+=[nums[i+1]]*nums[i] return arr
decompress-run-length-encoded-list
Python Solution (76.47%) || please suggest optimization
sanjam531
0
66
decompress run length encoded list
1,313
0.859
Easy
19,628
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1221077/80ms-Python3-(with-comments)
class Solution(object): def decompressRLElist(self, nums): """ :type nums: List[int] :rtype: List[int] """ #We create a variable to save the result result = [] #We iterate through the the starting indexes of each pair in any even elements list for i in range(0,len...
decompress-run-length-encoded-list
80ms, Python3 (with comments)
Akshar-code
0
46
decompress run length encoded list
1,313
0.859
Easy
19,629
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1161738/Python-One-Liner
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: return list(itertools.chain(*[[nums[i + 1]]*nums[i] for i in range(0, len(nums) - 1, 2)]))
decompress-run-length-encoded-list
Python One Liner
BrendMU
0
103
decompress run length encoded list
1,313
0.859
Easy
19,630
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1010107/Python3-solution.-very-straightforward
class Solution: def decompressRLElist(self, nums: List[int]) -> List[int]: k = 0 arr = [] while k < len(nums): freq = nums[k] val = nums[k+1] for i in range(freq): arr.append(val) k += 2 return arr
decompress-run-length-encoded-list
Python3 solution. very straightforward
izekchen0222
0
74
decompress run length encoded list
1,313
0.859
Easy
19,631
https://leetcode.com/problems/matrix-block-sum/discuss/711729/Python-DP-O(m*n)
class Solution: def matrixBlockSum(self, mat: List[List[int]], K: int) -> List[List[int]]: m, n = len(mat), len(mat[0]) mat[:] = [[0] * (n + 1)] + [[0] + row for row in mat] res = [[0] * n for i in range(m)] for i in range(1, m + 1): for j in range(1, n + 1): ...
matrix-block-sum
Python DP O(m*n)
SWeszler
8
1,100
matrix block sum
1,314
0.754
Medium
19,632
https://leetcode.com/problems/matrix-block-sum/discuss/1521997/Python-Two-Approaches%3A-Easy-to-understand-w-Explanation
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m, n = len(mat), len(mat[0]) result = [[0 for _ in range(n)] for _ in range(m)] for i in range(m): for j in range(n): result[i][j] = sum(sum(mat[x][max(0, j-k):min(n, j+k+1)...
matrix-block-sum
Python, Two Approaches: Easy-to-understand w Explanation
zayne-siew
7
478
matrix block sum
1,314
0.754
Medium
19,633
https://leetcode.com/problems/matrix-block-sum/discuss/1521997/Python-Two-Approaches%3A-Easy-to-understand-w-Explanation
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m, n = len(mat), len(mat[0]) # Calculate the prefix sum prefix = mat[:][:] # essentially copies the entire array for i in range(m): for j in range(n): prefix[i][j] += ...
matrix-block-sum
Python, Two Approaches: Easy-to-understand w Explanation
zayne-siew
7
478
matrix block sum
1,314
0.754
Medium
19,634
https://leetcode.com/problems/matrix-block-sum/discuss/1799507/Python-easy-to-read-and-understand-or-Range-query-sum-2D
class Solution: def sumRegion(self, matrix, row1, col1, row2, col2): ans = 0 for i in range(row1, row2+1): x1 = matrix[i][col2] x2 = 0 if col1 == 0 else matrix[i][col1-1] ans += x1-x2 return ans def matrixBlockSum(self, mat: List[List[int]], k: in...
matrix-block-sum
Python easy to read and understand | Range query sum 2D
sanial2001
1
208
matrix block sum
1,314
0.754
Medium
19,635
https://leetcode.com/problems/matrix-block-sum/discuss/1524791/Python3-Self-explanatory-Prefix-Sum-Based-Solution
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: """ [+][ ][ ][-] [ ][a][b][ ] [ ][c][d][ ] dp[d] = dp[b] + dp[c] - dp[a] + mat[d] [-][ ][ ][+] lower_right upper_right lower_left upper_l...
matrix-block-sum
[Python3] Self-explanatory Prefix-Sum Based Solution
nick19981122
1
263
matrix block sum
1,314
0.754
Medium
19,636
https://leetcode.com/problems/matrix-block-sum/discuss/477111/Python3-prefix-sum
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m, n = len(mat), len(mat[0]) prefix = [[0]*(n+1) for _ in range(m+1)] for i in range(m): for j in range(n): prefix[i+1][j+1] = mat[i][j] + prefix[i][j+1] + prefix[i+1][j] -...
matrix-block-sum
[Python3] prefix sum
ye15
1
183
matrix block sum
1,314
0.754
Medium
19,637
https://leetcode.com/problems/matrix-block-sum/discuss/2642852/Python3-or-Solved-Using-Prefix-Sum
class Solution: #Time-Complexity: O(m^2*n) #Space-Complexity: O(m*n) def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m, n = len(mat), len(mat[0]) prefix_sum = [[None for _ in range(n)] for z in range(m)] for a in range(m): prefix_sum[a][0] = mat...
matrix-block-sum
Python3 | Solved Using Prefix Sum
JOON1234
0
46
matrix block sum
1,314
0.754
Medium
19,638
https://leetcode.com/problems/matrix-block-sum/discuss/2458482/Python3-Solution-with-using-prefix-sum
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: n, m = len(mat), len(mat[0]) """ // _sum[i][j] is sum of all elements from rectangle [0,0,i,j] """ _sum = [[0] * (m + 1) for _ in range(n + 1)] for i in range(...
matrix-block-sum
[Python3] Solution with using prefix sum
maosipov11
0
57
matrix block sum
1,314
0.754
Medium
19,639
https://leetcode.com/problems/matrix-block-sum/discuss/2397383/Python3-Sliding-Window
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m, n = len(mat), len(mat[0]) # sum rows ans = [r[:] for r in mat] for i in range(m): ans[i][0] = sum(mat[i][:k+1]) for j in range(1,n): ans[i][j] = ans[i...
matrix-block-sum
[Python3] Sliding Window
ruosengao
0
42
matrix block sum
1,314
0.754
Medium
19,640
https://leetcode.com/problems/matrix-block-sum/discuss/2353211/Simple-prefix-solution-uses-range-sum-query
class Solution: def matrixBlockSum(self, matrix: List[List[int]], k: int) -> List[List[int]]: rows,cols = len(matrix), len(matrix[0]) self.dp = [[0]*(cols+1) for _ in range(rows+1)] for r in range(rows): # for Prefix sum of 2d array prefix = 0 for c in range(cols...
matrix-block-sum
Simple prefix solution uses range sum query
sidrAG
0
45
matrix block sum
1,314
0.754
Medium
19,641
https://leetcode.com/problems/matrix-block-sum/discuss/2074059/Python-Prefix-Sum-O(M*N)-Solution
class Solution: def matrixBlockSum(self, nums: List[List[int]], k: int) -> List[List[int]]: # create prefix sum (cummulative sum) where nums[i][j] denotes sum of all elements from [0,0] to [i][j] # for sum from (r1,c1) to (r2,c2), we get ans = nums[r2][c2]-nums[r2][c1-1]-nums[r1-1][c2]+nums[r1-1][c1-1] ...
matrix-block-sum
Python Prefix Sum O(M*N) Solution
dsalgobros
0
94
matrix block sum
1,314
0.754
Medium
19,642
https://leetcode.com/problems/matrix-block-sum/discuss/2069089/Python-or-DP
class Solution: def matrixBlockSum(self, ma: List[List[int]], k: int) -> List[List[int]]: n = len(ma) m = len(ma[0]) def isval(x,y): if x<0 or y<0 or x>=n or y>=m: return False return True t = [[0 for i in range(m)]for j in range(n)] fo...
matrix-block-sum
Python | DP
Shivamk09
0
58
matrix block sum
1,314
0.754
Medium
19,643
https://leetcode.com/problems/matrix-block-sum/discuss/1934562/solution-using-prefix-sum
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: mat.insert(0,[0]*(len(mat[0]))) for i in mat: i.insert(0,0) compute=[[0 for i in range(len(mat[0]))] for j in range(len(mat))] def pre_compute(): for i in range...
matrix-block-sum
solution using prefix sum
prateek4463
0
55
matrix block sum
1,314
0.754
Medium
19,644
https://leetcode.com/problems/matrix-block-sum/discuss/1652678/python-simple-solution-or-95.37
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m,n = len(mat),len(mat[0]) P = [[0]*(n+1) for _ in range(m+1)] for i in range(1, m+1): for j in range(1, n+1): P[i][j] = P[i-1][j] + P[i][j-1] - P[i-1][j-1] + mat[i-1][j-1] ...
matrix-block-sum
python simple solution | 95.37%
1579901970cg
0
279
matrix block sum
1,314
0.754
Medium
19,645
https://leetcode.com/problems/matrix-block-sum/discuss/1245267/Python-Prefix-Sum-based-solution
class Solution: def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]: m = len(mat) n = len(mat[0]) sumM = [[0]*n for _ in range(m)] for i in range(m): cs = 0 for j in range(n): cs += mat[i][j] ...
matrix-block-sum
Python Prefix Sum based solution
worker-bee
0
175
matrix block sum
1,314
0.754
Medium
19,646
https://leetcode.com/problems/matrix-block-sum/discuss/1123134/Python3-Six-lines-different-than-prefix-sum-88ms-(99)-speed-97-memory
class Solution: def matrixBlockSum(self, mat: List[List[int]], K: int) -> List[List[int]]: def nearby_sum(seq: Sequence) -> Iterable[int]: total = sum(seq[:K]) for i, n in enumerate(seq): total += (seq[i+K] if i+K < len(seq) else 0) - (seq[i-K-1] if i-K-1 >= 0 else 0)...
matrix-block-sum
[Python3] Six lines - different than prefix sum - 88ms (99%) speed, 97% memory
travisjungroth
0
199
matrix block sum
1,314
0.754
Medium
19,647
https://leetcode.com/problems/matrix-block-sum/discuss/483502/Python-3-(Cumulative-Sum)-(beats-~96)
class Solution: def matrixBlockSum(self, G: List[List[int]], K: int) -> List[List[int]]: M, N, G[0] = len(G), len(G[0]), list(itertools.accumulate(G[0])); A = [[0]*N for _ in range(M)] for i in range(1,M): s = 0 for j in range(N): s += G[i][j]; G[i][j] = s + G[i-1][j] ...
matrix-block-sum
Python 3 (Cumulative Sum) (beats ~96%)
junaidmansuri
0
476
matrix block sum
1,314
0.754
Medium
19,648
https://leetcode.com/problems/matrix-block-sum/discuss/477222/Python3-brute-force-and-DP
class Solution: def matrixBlockSum(self, mat: List[List[int]], K: int) -> List[List[int]]: m,n,res,dp=len(mat),len(mat[0]),[],[] for row in mat: res.append([0]*n) dp.append([0]*(n+1)) dp.append([0]*(n+1)) for i in range(m): for j in range(n): dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j]+mat[i]...
matrix-block-sum
Python3 brute force and DP
jb07
0
185
matrix block sum
1,314
0.754
Medium
19,649
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/514777/Python3-96ms-solution
class Solution: def __init__(self): self.summary = 0 def sumEvenGrandparent(self, root: TreeNode) -> int: self.walk(root, False, False) return self.summary def walk(self, node: TreeNode, parent_even: bool, grand_parent_even: bool): if node is None: return ...
sum-of-nodes-with-even-valued-grandparent
Python3 96ms solution
tjucoder
7
740
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,650
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2085065/Python-iterative-stack-easy-to-understand-O(N)-time-and-O(N)-space
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: root.parent = None root.grandparent = None result = 0 stack = [root] while len(stack): node = stack.pop() if node.left: node.left.parent = node ...
sum-of-nodes-with-even-valued-grandparent
Python iterative stack easy to understand O(N) time and O(N) space
tushar-rishav
2
22
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,651
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/1763985/Python-Simple-Solution
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: ans = 0 def utility(current: TreeNode, parent=-1, grandparent=-1): nonlocal ans if current is None: return 0 if grandparent % 2 == 0: ans += current.val ...
sum-of-nodes-with-even-valued-grandparent
Python Simple Solution
anCoderr
2
96
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,652
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2732359/Recursive-or-Time-Complexity-O(N)
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: def helper(grandparent, parent, node): if not node:return if grandparent and grandparent.val%2 == 0:self.ans += node.val helper(parent, node, node.left) helper(parent, node, node.right) ...
sum-of-nodes-with-even-valued-grandparent
Recursive | Time Complexity - O(N)
Rahul-Krishna
1
27
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,653
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2329403/Easiest-Solution-To-Understand-Beats-90-Beginner-DFS-Solution
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: evenGrandParent = [] def dfs(node, parent=None, grandParent=None): if node is None: return if grandParent and grandParent % 2 == 0: nonlocal evenGrandPar...
sum-of-nodes-with-even-valued-grandparent
Easiest Solution To Understand - Beats 90% - Beginner DFS Solution
7yler
1
44
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,654
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/483529/Python-3-(DFS)-(beats-~93)
class Solution: def sumEvenGrandparent(self, R: TreeNode) -> int: S = [0] def dfs(N): if N and not N.val % 2: if N.left: if N.left.left: S[0] += N.left.left.val if N.left.right: S[0] += N.left.right.val if N.right: ...
sum-of-nodes-with-even-valued-grandparent
Python 3 (DFS) (beats ~93%)
junaidmansuri
1
308
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,655
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2715007/95-Accepted-or-Using-Deque-or-Easy-to-Understand-or-Python
class Solution(object): def sumEvenGrandparent(self, root): q = deque() q.append(root) ans = 0 while q: for _ in range(len(q)): p = q.popleft() if p.val % 2 == 0: if p.left: if p.left.left: ...
sum-of-nodes-with-even-valued-grandparent
95% Accepted | Using Deque | Easy to Understand | Python
its_krish_here
0
5
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,656
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2695884/Python3-Simple-Solution
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: self.res = 0 def DFS(r, p, gp): if r: if gp % 2 == 0: self.res += r.val DFS(r.left, r.val, p) DFS(r.right, r.val, p) DFS(root...
sum-of-nodes-with-even-valued-grandparent
Python3 Simple Solution
mediocre-coder
0
3
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,657
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2685269/python-iterative-solution
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: stk=[[root,None,None]] ans=0 while stk: temp=stk.pop() if temp[2] and not temp[2]%2: ans+=temp[0].val if temp[0].left: stk.append([temp[0].left,temp[0].va...
sum-of-nodes-with-even-valued-grandparent
python iterative solution
benon
0
8
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,658
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2623208/Simple-Traversal-or-Python
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: ans = [0] def pre(root): if not root: return if root.val&amp;1 == 0: ans[0] += root.left.left.val if root.left and root.left.left else 0 ans[0] += root.left.ri...
sum-of-nodes-with-even-valued-grandparent
Simple Traversal | Python
RajatGanguly
0
11
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,659
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2531238/Easy-Python-Solution-or-bfs
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: stack = [] stack.append(root) ans = 0 while len(stack): size = len(stack) while size: node = stack[0] del stack[0] if...
sum-of-nodes-with-even-valued-grandparent
Easy Python Solution | bfs
coolakash10
0
11
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,660
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2497107/Clean-and-easy-to-understand-python-solution
class Solution: def __init__(self): self.total = 0 def sumEvenGrandparent(self, root: TreeNode) -> int: if root.val % 2 == 0: if root.left: if root.left.left: self.total += root.left.left.val if root.left.right: ...
sum-of-nodes-with-even-valued-grandparent
Clean and easy to understand python solution
aruj900
0
17
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,661
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2401645/python-easy-pisy-soln-dfs
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: #algorithm just preserve their parents in stack like [node,[parents.vaues]] stk=[[root,[]]] ans=0 while stk: # print(stk) temp=stk.pop() try: if temp[1][-2]%2==0: ...
sum-of-nodes-with-even-valued-grandparent
python easy pisy soln dfs
benon
0
12
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,662
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2207764/python-3-or-simple-dfs
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: def helper(root, parentVal, grandparentVal): if root is None: return 0 return ((1 - grandparentVal % 2) * root.val + helper(root.left, root.val, parentVal) + ...
sum-of-nodes-with-even-valued-grandparent
python 3 | simple dfs
dereky4
0
16
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,663
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/2112802/Just-Some-Conditional-Cases-with-Explanation-or-DFS-Preorder-and-Recursion-or-104ms-or
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: s = 0 def dfs(root): nonlocal s if root is None: return if root.val % 2 == 0: if root.left is not None and root.left.left is not None: s += root.left.left.val ...
sum-of-nodes-with-even-valued-grandparent
Just Some Conditional Cases with Explanation | DFS Preorder & Recursion | 104ms |
omkulkarni22
0
9
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,664
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/1631510/Easy-Recursion
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: self.sums = 0 def helper(root): if root==None: return if root.left==None and root.right==None: return if root.val %...
sum-of-nodes-with-even-valued-grandparent
Easy Recursion
Manashi_itsme
0
19
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,665
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/1178496/Python-3-dfs-plus-helper-function-for-beginners
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: #global variable to count values self.c = 0 def rec(root): if root: #check if value is even if root.val%2==0: #find the values of grandchildren k = value(root) ...
sum-of-nodes-with-even-valued-grandparent
[Python 3] dfs plus helper function for beginners
rajsinxh
0
67
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,666
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/1162423/93.91-Faster-Runtime.-Simple-Python-Solution.
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: level = [(root,None,None)] summ = 0 while level: next_level = [] for node,parent,grandParent in level: if grandParent and grandParent.val%2 == 0: summ += node.val ...
sum-of-nodes-with-even-valued-grandparent
93.91% Faster Runtime. Simple Python Solution.
bhagwataditya226
0
34
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,667
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/753788/Intuitive-Python-Recursive-DFS-beats-85-with-Comments!
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: total = 0 def helper(node): nonlocal total # Return when we run out of nodes. if not node: return # If our current nodes val is even. if node.val % 2 == 0:...
sum-of-nodes-with-even-valued-grandparent
Intuitive Python Recursive DFS, beats 85% with Comments!
Pythagoras_the_3rd
0
66
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,668
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/679138/PythonPython3-Sum-of-Nodes-with-Even-Valued-Grandparent
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: s = 0 #'set sum of nodes value to zero if not root: return 0 if root.val%2==0: if root.left: if root.left.left: s += root.left.left.v...
sum-of-nodes-with-even-valued-grandparent
[Python/Python3] Sum of Nodes with Even-Valued Grandparent
newborncoder
0
95
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,669
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/478198/Python3-DFS-with-tracking
class Solution: ans = 0 def sumEvenGrandparent(self, root: TreeNode) -> int: def bfs(node: TreeNode, parent: TreeNode, grantParent: TreeNode): if grantParent and grantParent.val % 2 == 0: self.ans += node.val if node.left: bfs(node.left, node, par...
sum-of-nodes-with-even-valued-grandparent
[Python3] DFS with tracking
tp99
0
121
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,670
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/discuss/477116/Python3-depth-first-traversal
class Solution: def sumEvenGrandparent(self, root: TreeNode) -> int: if not root: return 0 #edge case ans = 0 #preorder dfs stack = [(root, None, None)] #node-parent-grandparent while stack: node, parent, grand = stack.pop() if grand and grand &amp; ...
sum-of-nodes-with-even-valued-grandparent
[Python3] depth-first traversal
ye15
0
81
sum of nodes with even valued grandparent
1,315
0.856
Medium
19,671
https://leetcode.com/problems/distinct-echo-substrings/discuss/1341886/Python-3-Rolling-hash-(5780ms)
class Solution: def distinctEchoSubstrings(self, text: str) -> int: n = len(text) def helper(size): base = 1 << 5 M = 10 ** 9 + 7 a = pow(base, size, M) t = 0 vis = defaultdict(set) vis_pattern = set() ans = 0 ...
distinct-echo-substrings
[Python 3] Rolling hash (5780ms)
chestnut890123
2
203
distinct echo substrings
1,316
0.497
Hard
19,672
https://leetcode.com/problems/distinct-echo-substrings/discuss/1419989/python-or-better-than-100-or-simple-bruteforce
class Solution(object): def distinctEchoSubstrings(self, text): n=len(text) ans=0 s=set() for i in range(1,n): for j in range(i//2+1,i+1): l=i+1-j temp=text[j-l:j] if temp==text[j:i+1]: s.add(temp) ...
distinct-echo-substrings
python | better than 100% | simple bruteforce
heisenbarg
0
166
distinct echo substrings
1,316
0.497
Hard
19,673
https://leetcode.com/problems/distinct-echo-substrings/discuss/477257/Python3-simple-accepted-solution
class Solution: def distinctEchoSubstrings(self, text: str) -> int: res = [] for i in range(len(text)): for j in range(i+1,len(text)+1): if len(text[i:j])%2==0 and text[i:j][:len(text[i:j])//2]==text[i:j][len(text[i:j])//2:] and text[i:j] not in res: res.append(text[i:j]) return len(res)
distinct-echo-substrings
Python3 simple accepted solution
jb07
0
78
distinct echo substrings
1,316
0.497
Hard
19,674
https://leetcode.com/problems/distinct-echo-substrings/discuss/477121/Python3-Brute-force-solution
class Solution: def distinctEchoSubstrings(self, text: str) -> int: ans = set() for i in range(len(text)-1): for j in range(i+1, (i+len(text))//2+1): if text[i:j] == text[j:2*j-i]: ans.add(text[i:j]) return len(ans)
distinct-echo-substrings
[Python3] Brute force solution
ye15
0
53
distinct echo substrings
1,316
0.497
Hard
19,675
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1219360/Python-Fast-and-Easy-Soln
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: left = 0 right = n ans = [] while True: if str(left).count("0")==0 and str(right).count("0")==0: ans.append(left) ans.append(right) break left+=1 ...
convert-integer-to-the-sum-of-two-no-zero-integers
Python Fast & Easy Soln
iamkshitij77
2
212
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,676
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/2812823/Python-Easy-Solution-Faster-Than-98.86
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: def check(num): while num>0: if num%10==0: return False num//=10 return True for i in range(1,n): t=n-i if check(t) and check(i): ...
convert-integer-to-the-sum-of-two-no-zero-integers
Python Easy Solution Faster Than 98.86%
DareDevil_007
1
49
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,677
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1115791/Python3-simple-solution-beats-100-user
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: for i in range(1,n): if '0' not in str(i) and '0' not in str(n-i): return [i,n-i]
convert-integer-to-the-sum-of-two-no-zero-integers
Python3 simple solution beats 100% user
EklavyaJoshi
1
108
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,678
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/915654/Python3-100-faster-100-less-memory-(16ms-14.1mb)
class Solution: def getNoZeroIntegers(self, n): for x in range(1, n): for c in str(x): if c == '0': break else: for y in str(tmp := n - x): if y =='0': break else: ...
convert-integer-to-the-sum-of-two-no-zero-integers
Python3 100% faster, 100% less memory (16ms, 14.1mb)
haasosaurus
1
363
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,679
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/477732/Python-3-(brute-force)-(two-lines)-(beats-100)-(24-ms)
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: for i in range(1,n): if '0' not in str(i) + str(n-i): return [i,n-i] - Junaid Mansuri - Chicago, IL
convert-integer-to-the-sum-of-two-no-zero-integers
Python 3 (brute force) (two lines) (beats 100%) (24 ms)
junaidmansuri
1
252
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,680
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/2069648/Using-while-loop-to-solve-22ms-Best-Faster-~97
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: a, b = 1, n - 1 while "0" in str(a) + str(b): a += 1 b -= 1 return [a, b]
convert-integer-to-the-sum-of-two-no-zero-integers
Using while loop to solve 22ms Best Faster ~97%
andrewnerdimo
0
51
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,681
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/2047550/Python-simple-solution
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: ans = [] for i in range(1, n): if '0' not in str(i) and '0' not in str(n-i): ans.append(i) ans.append(n-i) break return ans
convert-integer-to-the-sum-of-two-no-zero-integers
Python simple solution
StikS32
0
77
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,682
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1922973/Python-easy-solution-with-memory-less-than-97
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: for i in range(1, n+1): if str(i).count('0') == 0 and str(n - i).count('0') == 0: return [i, n-i]
convert-integer-to-the-sum-of-two-no-zero-integers
Python easy solution with memory less than 97%
alishak1999
0
78
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,683
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1879500/Python-or-Simple-Solution
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: num1 = 1 num2 = n-1 while True: if ('0' in str(num1)) or ('0' in str(num2)): num1 += 1 num2 -= 1 else: return [num1, num2]
convert-integer-to-the-sum-of-two-no-zero-integers
Python | Simple Solution
i_architect
0
66
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,684
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1848846/2-Lines-Python-Solution-oror-60-Faster-oror-Memory-less-than-97
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: for i in range(1,n): if '0' not in str(i)+str(n-i): return [i,n-i]
convert-integer-to-the-sum-of-two-no-zero-integers
2-Lines Python Solution || 60% Faster || Memory less than 97%
Taha-C
0
42
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,685
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1848846/2-Lines-Python-Solution-oror-60-Faster-oror-Memory-less-than-97
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: return next([i,n-i] for i in range(n) if '0' not in str(i)+str(n-i))
convert-integer-to-the-sum-of-two-no-zero-integers
2-Lines Python Solution || 60% Faster || Memory less than 97%
Taha-C
0
42
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,686
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1820531/python-solution
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: if n % 2 == 0: for i in range(n//2+1): if str(n//2-i).count('0') == 0 and str(n//2+i).count('0') == 0: return [n//2-i,n//2+i] else: for i in range(n//2+1): if...
convert-integer-to-the-sum-of-two-no-zero-integers
python solution
MS1301
0
31
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,687
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1533462/Python-Weird-Binary-Search
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: lo, hi = 1, n-1 while lo < hi: mid = (lo + hi) // 2 if '0' in str(n-mid) + str(mid): hi = mid + 1 else: return [mid,...
convert-integer-to-the-sum-of-two-no-zero-integers
[Python] Weird Binary Search
dev-josh
0
57
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,688
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/1106805/Python3-brute-force
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: for x in range(1, n//2+1): if "0" not in str(x) and "0" not in str(n-x): return [x, n-x]
convert-integer-to-the-sum-of-two-no-zero-integers
[Python3] brute-force
ye15
0
38
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,689
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/708012/simple-of-simple
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: a = 1 while True: b = n-a if '0' not in str(a) and \ '0' not in str(b): break a += 1 return [a, b]
convert-integer-to-the-sum-of-two-no-zero-integers
simple of simple
seunggabi
0
57
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,690
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/discuss/668370/Python-O(logN)-beats-100
class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: if n<10: return [1,n-1] a = int(str(n)[1:])+1 a = int(''.join(['1' if i == '0' else i for i in str(a)])) return [a,n-a]
convert-integer-to-the-sum-of-two-no-zero-integers
Python O(logN) beats 100%
AWDawson
0
123
convert integer to the sum of two no zero integers
1,317
0.56
Easy
19,691
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/489623/Python-Simple-Solution-Python-Memory-usage-less-than-100
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: count = 0 while a or b or c: if (a &amp; 1) | (b &amp; 1) != (c &amp; 1): if (c &amp; 1): count += 1 else: count += (a &amp; 1) + (b &amp; 1) a, b, c = a >> 1, b >> 1, c >> 1...
minimum-flips-to-make-a-or-b-equal-to-c
Python - Simple Solution - Python - Memory usage less than 100%
mmbhatk
5
339
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,692
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/477759/Python-3-(five-lines)-(beats-100)-(20-ms)
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: a, b, c, t, D = bin(a)[2:], bin(b)[2:], bin(c)[2:], 0, {'010':1, '100':1, '001':1, '110':2} M = max(len(a),len(b),len(c)) a, b, c = a.zfill(M), b.zfill(M), c.zfill(M) for i in range(M): t += D.get(a[i]+b[i]+c[i],0) ...
minimum-flips-to-make-a-or-b-equal-to-c
Python 3 (five lines) (beats 100%) (20 ms)
junaidmansuri
2
173
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,693
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/2808950/Python3-Solution-or-Bit-Manipulation
class Solution: def minFlips(self, a, b, c): count = lambda x : bin(x).count('1') return count((a | b) ^ c) + count(a &amp; b &amp; ~c)
minimum-flips-to-make-a-or-b-equal-to-c
✔ Python3 Solution | Bit Manipulation
satyam2001
1
21
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,694
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/2283071/Python3-Bit-Manipulation-Constant-Time-and-Memory
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: res = 0 for i in range(32): if (a &amp; 1) | (b &amp; 1) != (c &amp; 1): if (c &amp; 1) == 1: # (a &amp; 1) | (b &amp; 1) should be == 1 ; so changing any of a, b we can get 1 res += 1...
minimum-flips-to-make-a-or-b-equal-to-c
[Python3] Bit Manipulation Constant Time and Memory
samirpaul1
1
78
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,695
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/2721742/Python3-or-Clean-and-Concise-or-Bit-Manipulation
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: ans=0 for i in range(32): bit_a = (a&amp;(1<<i)) >> i bit_b = (b&amp;(1<<i)) >> i bit_c = (c&amp;(1<<i)) >> i if bit_a | bit_b != bit_c: ans+=max(1,bit_a + bit_b) ...
minimum-flips-to-make-a-or-b-equal-to-c
[Python3] | Clean & Concise | Bit Manipulation
swapnilsingh421
0
6
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,696
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/2709256/Simple-python-code-with-explanation
class Solution: def minFlips(self, a, b, c): #create a variable count to store flips count = 0 #this while loop works untill #all the current bits of a , b , c = 0 while (a!= 0 or b!=0 or c!=0): #store the (a&amp;1)last bit of a in x x = (a&amp;1) ...
minimum-flips-to-make-a-or-b-equal-to-c
Simple python code with explanation
thomanani
0
2
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,697
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/2681248/Python3-Solution-oror-O(log-N)-Time-and-O(1)-Space-Complexity
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: if a|b==c: return 0 flipCount=0 while a>0 or b>0 or c>0: if (a|b)&amp;1 != c&amp;1: if c&amp;1==1: flipCount+=1 else: if a&amp;1=...
minimum-flips-to-make-a-or-b-equal-to-c
Python3 Solution || O(log N) Time & O(1) Space Complexity
akshatkhanna37
0
1
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,698
https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/discuss/2424293/Python-Bit-Manipulation-95-faster
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: count = 0 while a != 0 or b!= 0 or c!=0: x , y, z = b&amp;1,a&amp;1,c&amp;1 if (x|y)!=z: if x == 1 and y == 1: count += 2 else: count+=1 ...
minimum-flips-to-make-a-or-b-equal-to-c
[Python] Bit Manipulation 95% faster
Nish786
0
51
minimum flips to make a or b equal to c
1,318
0.66
Medium
19,699