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/create-target-array-in-the-given-order/discuss/1691811/3-Methods-or-Python3
class Solution: def createTargetArray(self, nums, index): target = [] for i,value in zip(index, nums): target.insert(i,value) return target obj = Solution() print(obj.createTargetArray([0,1,2,3,4],[0,1,2,2,1]))
create-target-array-in-the-given-order
3 Methods | Python3 🐍
hritik5102
0
57
create target array in the given order
1,389
0.859
Easy
20,900
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/1256771/python-solution-easy-to-understand.
class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: target = [] for i in range(len(nums)): target.insert(index[i], nums[i]) return target
create-target-array-in-the-given-order
python solution - easy to understand.
jayesh_kaushik
0
71
create target array in the given order
1,389
0.859
Easy
20,901
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/1006014/Python-or-92.56-or-3-Methods-to-solve
class Solution: def createTargetArray(self, nums, index): target = [0]*len(nums) target_copy = [0]*len(nums) for i,v in zip(index,nums): if target[i]: for j in range(i+1,len(target_copy)): target[j] = target_copy[j-1] target[i]=...
create-target-array-in-the-given-order
Python | 92.56% | 3 Methods to solve
hritik5102
0
174
create target array in the given order
1,389
0.859
Easy
20,902
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/1006014/Python-or-92.56-or-3-Methods-to-solve
class Solution: def createTargetArray(self, nums, index): target = [] for i in range(len(nums)): target = target[:index[i]] + [nums[i]] + target[index[i]:] return target
create-target-array-in-the-given-order
Python | 92.56% | 3 Methods to solve
hritik5102
0
174
create target array in the given order
1,389
0.859
Easy
20,903
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/1006014/Python-or-92.56-or-3-Methods-to-solve
class Solution: def createTargetArray(self, nums, index): target = [] for i,value in zip(index, nums): target.insert(i,value) return target obj = Solution() print(obj.createTargetArray([0,1,2,3,4],[0,1,2,2,1]))
create-target-array-in-the-given-order
Python | 92.56% | 3 Methods to solve
hritik5102
0
174
create target array in the given order
1,389
0.859
Easy
20,904
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/955156/Python-Linked-List-greater99.4Easiest-Approach
class Solution: def createTargetArray(self, nums, index): head = Node(nums[0]) # We always start at nums[0]. ll = LL(head) # Initialise our linked list. for i in range(1, len(index)): # We set our head node already. Skip. ll.insert(nums[i], index[i]) # Very simple insertion!...
create-target-array-in-the-given-order
Python Linked List [>99.4%][Easiest Approach]
StephenLalor
0
159
create target array in the given order
1,389
0.859
Easy
20,905
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/692454/Python-3-Create-Target-Array-in-the-Given-Order
class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: result = [] for i in range(len(nums)): result.insert(index[i],nums[i]) return result
create-target-array-in-the-given-order
Python 3 Create Target Array in the Given Order
abhijeetmallick29
0
135
create target array in the given order
1,389
0.859
Easy
20,906
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/674094/Python3-solution-without-using-list.insert()
class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: target = [None] * len(nums) for k in range(len(nums)): if target[index[k]] == None: target[index[k]] = nums[k] else: l = index[k] + 1 whil...
create-target-array-in-the-given-order
Python3 solution without using list.insert()
adb786
0
225
create target array in the given order
1,389
0.859
Easy
20,907
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/547268/Python3-brute-force
class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: ans = [] for i, x in zip(index, nums): ans.insert(i, x) return ans
create-target-array-in-the-given-order
[Python3] brute-force
ye15
0
100
create target array in the given order
1,389
0.859
Easy
20,908
https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/836690/Python-3-24-ms-Solution-98.62
class Solution: def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: result = [] for i in range(0, len(index)): # insertion is guaranteed to be valid result.insert(index[i], nums[i]) # shift then insert value return result
create-target-array-in-the-given-order
Python 3 24 ms Solution 98.62%
Skyfall2017
-1
250
create target array in the given order
1,389
0.859
Easy
20,909
https://leetcode.com/problems/four-divisors/discuss/547308/Python3-Short-Easy-Solution
class Solution: def sumFourDivisors(self, nums: List[int]) -> int: res = 0 for num in nums: divisor = set() for i in range(1, floor(sqrt(num)) + 1): if num % i == 0: divisor.add(num//i) divisor.add(i) if...
four-divisors
[Python3] Short Easy Solution
localhostghost
22
2,500
four divisors
1,390
0.413
Medium
20,910
https://leetcode.com/problems/four-divisors/discuss/547208/Python3-use-a-helper-fn
class Solution: def sumFourDivisors(self, nums: List[int]) -> int: def fn(x): c = s = 0 for i in range(1, int(x**0.5)+1): if x % i == 0: c += 1 + (0 if x//i == i else 1) s += i + (0 if x//i == i else x//i) ...
four-divisors
[Python3] use a helper fn
ye15
0
85
four divisors
1,390
0.413
Medium
20,911
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/635713/Python3-dfs-solution-Check-if-There-is-a-Valid-Path-in-a-Grid
class Solution: directions = [[-1, 0], [0, 1], [1, 0], [0, -1]] streetDirections = { 1: [1, 3], 2: [0, 2], 3: [2, 3], 4: [1, 2], 5: [0, 3], 6: [0, 1] } def hasValidPath(self, grid: List[List[int]]) -> bool: m, n = len(grid), len(grid[0]) def dfs(...
check-if-there-is-a-valid-path-in-a-grid
Python3 dfs solution - Check if There is a Valid Path in a Grid
r0bertz
2
391
check if there is a valid path in a grid
1,391
0.472
Medium
20,912
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/1486702/Python3-readable-solution-with-comments
class Solution: # define direction identifiers left, right, up, down = 0, 1, 2, 3 # define possible directions to move from a given street moves = { 1: {left, right}, 2: {up, down}, 3: {left, down}, 4: {down, right}, 5: {left, up}, 6: {up, right} ...
check-if-there-is-a-valid-path-in-a-grid
Python3 readable solution with comments
ac_h_illes
1
185
check if there is a valid path in a grid
1,391
0.472
Medium
20,913
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/547226/Python3-graph-traversal
class Solution: def hasValidPath(self, grid: List[List[int]]) -> bool: m, n = len(grid), len(grid[0]) #dimension graph = dict() for i in range(m): for j in range(n): if grid[i][j] == 1: graph[i, j] = [(i, j-1), (i, j+1)] elif grid[i][j] ...
check-if-there-is-a-valid-path-in-a-grid
[Python3] graph traversal
ye15
1
224
check if there is a valid path in a grid
1,391
0.472
Medium
20,914
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/2009081/Python3-solution
class Solution: def hasValidPath(self, grid: List[List[int]]) -> bool: d = { # direction 'E': (0,1), 'W': (0,-1), 'N': (-1,0), 'S': (1,0), } valid_path = { 1: {'E': [1, 3, 5], 'W': [1, 4, 6]}, 2: {'N': [2, 3, 4], 'S': [2, 5, 6]}, 3: {'W': [1, 4...
check-if-there-is-a-valid-path-in-a-grid
Python3 solution
dalechoi
0
40
check if there is a valid path in a grid
1,391
0.472
Medium
20,915
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/547245/Python-3-BFS
class Solution: def hasValidPath(self, grid: List[List[int]]) -> bool: self.m, self.n, self.res = len(grid), len(grid[0]), False self.vis = [[0] * (self.n) for _ in range(self.m)] def inArea(x, y): return x >= 0 and x < self.m and y >= 0 and y < self.n #...
check-if-there-is-a-valid-path-in-a-grid
[Python 3] BFS
cr_496352127
0
101
check if there is a valid path in a grid
1,391
0.472
Medium
20,916
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/548292/Python-DFS-and-Bit-Manipulation-(14-lines)
class Solution(object): def hasValidPath(self, grid): streets, m, n = [0, 56, 146, 152, 176, 26, 50], 3*len(grid), 3*len(grid[0]) def get(r, c): return 1 &amp; ((0 <= r < m and 0 <= c < n) and (streets[grid[r/3][c/3]] >> 3*(r%3)+(c%3))) stack, seen = [(1,1)], {(1, 1)} wh...
check-if-there-is-a-valid-path-in-a-grid
[Python] DFS and Bit Manipulation (14 lines)
leetcoder289
-1
117
check if there is a valid path in a grid
1,391
0.472
Medium
20,917
https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/discuss/547415/Python-BFS-short-and-readable-with-explanation
class Solution: def hasValidPath(self, grid: List[List[int]]) -> bool: if not grid or not grid[0]: return False M, N = len(grid), len(grid[0]) left, right, up, down = (0,-1), (0,1), (-1,0), (1,0) direction = { 1: (left, right), 2: (up, down), 3: (left, down), 4: ...
check-if-there-is-a-valid-path-in-a-grid
[Python] BFS, short & readable with explanation
browndog
-1
145
check if there is a valid path in a grid
1,391
0.472
Medium
20,918
https://leetcode.com/problems/longest-happy-prefix/discuss/2814375/Dynamic-programming-solution
class Solution: def longestPrefix(self, s: str) -> str: n = [0] + [None] * (len(s) - 1) for i in range(1, len(s)): k = n[i - 1] # trying length k + 1 while (k > 0) and (s[i] != s[k]): k = n[k - 1] if s[i] == s[k]: k += 1 ...
longest-happy-prefix
Dynamic programming solution
aknyazev87
1
24
longest happy prefix
1,392
0.45
Hard
20,919
https://leetcode.com/problems/longest-happy-prefix/discuss/2016882/python3-Solution-or-Z-Algorithm
class Solution: def longestPrefix(self, s: str) -> str: n = len(s) z = [0] * n l, r = 0, 0 for i in range(1, n): if i < r: z[i] = min(r - i, z[i - l]) while i + z[i] < n and s[z[i]] == s[i + z[i]]: z[i] += 1 if i + z...
longest-happy-prefix
python3 Solution | Z Algorithm
satyam2001
1
49
longest happy prefix
1,392
0.45
Hard
20,920
https://leetcode.com/problems/longest-happy-prefix/discuss/2842457/Python-KMP-algorithm-faster-than-73.93
class Solution: def longestPrefix(self, s: str) -> str: table = [0 for _ in range(len(s))] longest_prefix = 0 for j in range(1, len(s)): while longest_prefix>0 and s[longest_prefix]!=s[j]: longest_prefix = table[longest_prefix-1] if s[longest_prefix]==...
longest-happy-prefix
Python KMP algorithm faster than 73.93%
amy279
0
1
longest happy prefix
1,392
0.45
Hard
20,921
https://leetcode.com/problems/longest-happy-prefix/discuss/2315799/Short-Python3-implementation-with-Rolling-Hash
class Solution: def longestPrefix(self, s: str) -> str: a, m, p = 1103515245, 2**31, 1 ans = -1 prefix_hash, suffix_hash = 0, 0 for i in range(len(s)-1): prefix_hash = (prefix_hash * a + ord(s[i])) % m suffix_hash = (suffix_hash + ord(s[-i-1]) * p) % m ...
longest-happy-prefix
Short Python3 implementation with Rolling Hash
metaphysicalist
0
33
longest happy prefix
1,392
0.45
Hard
20,922
https://leetcode.com/problems/longest-happy-prefix/discuss/965771/Python3-Solution
class Solution: def longestPrefix(self, s: str) -> str: ans = "" for i in range(len(s)): if(i!=len(s)-1): if(s[:i+1] == s[len(s)-i-1:]): # print(s[:i+1],s[:-i][::-1]) if len(s[:i+1])>len(ans): ans = "" ...
longest-happy-prefix
Python3 Solution
swap2001
0
84
longest happy prefix
1,392
0.45
Hard
20,923
https://leetcode.com/problems/longest-happy-prefix/discuss/547251/Python-3-Straight-Forward
class Solution: def longestPrefix(self, s: str) -> str: lens, maxStr = len(s), "" for i in range(lens - 1): # Slice - Prefix and suffix comparison if s[:(i + 1)] == s[(lens - i - 1):]: # Update the result maxStr = s[:(i + 1)] return max...
longest-happy-prefix
[Python 3] Straight Forward
cr_496352127
0
41
longest happy prefix
1,392
0.45
Hard
20,924
https://leetcode.com/problems/longest-happy-prefix/discuss/547247/Python3-one-line
class Solution: def longestPrefix(self, s: str) -> str: return next((s[:i] for i in reversed(range(1, len(s))) if s[:i] == s[-i:]), "")
longest-happy-prefix
[Python3] one-line
ye15
0
53
longest happy prefix
1,392
0.45
Hard
20,925
https://leetcode.com/problems/longest-happy-prefix/discuss/547247/Python3-one-line
class Solution: def longestPrefix(self, s: str) -> str: MOD = 1_000_000_007 ii = -1 p = 1 prefix = suffix = 0 for i in range(len(s)-1): prefix = (26*prefix + ord(s[i]) - 97) % MOD suffix = ((ord(s[~i]) - 97)*p + suffix) % MOD if prefix ...
longest-happy-prefix
[Python3] one-line
ye15
0
53
longest happy prefix
1,392
0.45
Hard
20,926
https://leetcode.com/problems/longest-happy-prefix/discuss/1810048/Python-beginner-code
class Solution: def longestPrefix(self, s: str) -> str: lps = [0]*len(s) curr = 1 pre = 0 while curr < len(s): if s[curr] == s[pre]: lps[curr] = pre + 1 curr +=1 pre+=1 else: if pre == 0: ...
longest-happy-prefix
Python beginner code
Umarabdullah101
-1
57
longest happy prefix
1,392
0.45
Hard
20,927
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2103066/PYTHON-or-Simple-python-solution
class Solution: def findLucky(self, arr: List[int]) -> int: charMap = {} for i in arr: charMap[i] = 1 + charMap.get(i, 0) res = [] for i in charMap: if charMap[i] == i: res.append(i) ...
find-lucky-integer-in-an-array
PYTHON | Simple python solution
shreeruparel
1
145
find lucky integer in an array
1,394
0.636
Easy
20,928
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1891347/Simple-python-solution
class Solution: def findLucky(self, arr: List[int]) -> int: ans=[] d={} for ar in arr: if ar in d: d[ar]+=1 else: d[ar]=1 for key in d: if key ==d[key]: ans.append(key) if len(ans)==0: ...
find-lucky-integer-in-an-array
Simple python solution
Buyanjargal
1
84
find lucky integer in an array
1,394
0.636
Easy
20,929
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1831818/1-Line-Python-Solution-oror-10-Fast-oror-Memory-less-than-99
class Solution: def findLucky(self, arr: List[int]) -> int: return max([a for a in arr if arr.count(a)==a], default=-1)
find-lucky-integer-in-an-array
1-Line Python Solution || 10% Fast || Memory less than 99%
Taha-C
1
71
find lucky integer in an array
1,394
0.636
Easy
20,930
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1139094/Python-pythonic-wo-counter
class Solution: def findLucky(self, arr: List[int]) -> int: dct = {} for i in arr: dct[i] = dct.get(i, 0) + 1 return max([key for key, value in dct.items() if key == value], default=-1)
find-lucky-integer-in-an-array
[Python] pythonic, w/o counter
cruim
1
110
find lucky integer in an array
1,394
0.636
Easy
20,931
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2841216/Simple-Python-solution-using-Counter
class Solution: def findLucky(self, arr: List[int]) -> int: count = Counter(arr) ans = float("-inf") for k,v in count.items(): if k == v: ans = max(ans,k) return -1 if ans == float("-inf") else ans
find-lucky-integer-in-an-array
Simple Python solution using Counter
aruj900
0
1
find lucky integer in an array
1,394
0.636
Easy
20,932
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2790597/simple-and-easy-to-understand-(dont-even-need-explaining)
class Solution: def findLucky(self, arr: List[int]) -> int: a=[] for i in arr: if arr.count(i)==i: a.append(i) return max(a) if len(a)>0 else -1
find-lucky-integer-in-an-array
simple and easy to understand (dont even need explaining)
neetikumar42
0
7
find lucky integer in an array
1,394
0.636
Easy
20,933
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2786762/PYTHON-100-EASY-TO-UNDERSTANDSIMPLECLEAN
class Solution: def findLucky(self, arr: List[int]) -> int: luckyNumbers = [] for i in range(len(arr)): if arr[i] == arr.count(arr[i]): luckyNumbers.append(arr[i]) if len(luckyNumbers) == 0: return -1 else: return max(luckyNumbers)
find-lucky-integer-in-an-array
🔥PYTHON 100% EASY TO UNDERSTAND/SIMPLE/CLEAN🔥
YuviGill
0
4
find lucky integer in an array
1,394
0.636
Easy
20,934
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2779696/Find-Lucky-Number
class Solution: def findLucky(self, arr: List[int]) -> int: dic = {} my_list = [] for i in arr: dic[i]=dic.get(i, 0)+1 for k,v in dic.items(): if k==v: my_list.append(k) ans = max(my_list, default=-1) return ans
find-lucky-integer-in-an-array
Find Lucky Number
kashifnawab5
0
1
find lucky integer in an array
1,394
0.636
Easy
20,935
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2665338/Easy-Python-Solution-Using-Dictionary
class Solution: def findLucky(self, arr: List[int]) -> int: dic={} for i in arr: if i not in dic: dic[i]=1 else: dic[i]+=1 res=-1 for k,v in dic.items(): if v==k: res=max(v,res) return res
find-lucky-integer-in-an-array
Easy Python Solution Using Dictionary
ankitr8055
0
5
find lucky integer in an array
1,394
0.636
Easy
20,936
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2613929/Python-dictionary
class Solution: def findLucky(self, arr: List[int]) -> int: freq = dict() for i in range(len(arr)): if arr[i] not in freq: freq[arr[i]] = 1 else: freq[arr[i]] += 1 # reverse sort based on keys for key in sorted(fre...
find-lucky-integer-in-an-array
Python dictionary
aj1904
0
7
find lucky integer in an array
1,394
0.636
Easy
20,937
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2380876/simple
class Solution: def findLucky(self, arr: List[int]) -> int: d = Counter(arr) ans = -1 for key,value in d.items(): if key == value: ans = max(ans, value) return ans
find-lucky-integer-in-an-array
simple
ellie_aa
0
29
find lucky integer in an array
1,394
0.636
Easy
20,938
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2342331/Easy-python-hashmap
class Solution: def findLucky(self, arr: List[int]) -> int: max_=-1 freq = {} for i in arr: if i in freq: freq[i]+=1 else: freq[i]=1 for i in freq: if freq[i]==i: max_=max(max_,i) return max_
find-lucky-integer-in-an-array
Easy python hashmap
sunakshi132
0
45
find lucky integer in an array
1,394
0.636
Easy
20,939
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2234531/Beginner-Friendly-Explanation-oror-68ms-Faster-Than-79-oror-Python
class Solution: def findLucky(self, arr: List[int]) -> int: # Set up a Python dictionary object to store each number and its number of occurrences. int_count = {} # Build our dictionary. for i in arr: if i not in int_count: int_count.setdefault(i,...
find-lucky-integer-in-an-array
Beginner Friendly Explanation || 68ms, Faster Than 79% || Python
cool-huip
0
58
find lucky integer in an array
1,394
0.636
Easy
20,940
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2047559/Python-simple-solution
class Solution: def findLucky(self, arr: List[int]) -> int: ans = [] for i in arr: if arr.count(i) == i: ans.append(i) return max(ans) if ans else -1
find-lucky-integer-in-an-array
Python simple solution
StikS32
0
64
find lucky integer in an array
1,394
0.636
Easy
20,941
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/2036766/Python3-using-counter-and-max
class Solution: def findLucky(self, arr: List[int]) -> int: frequency = Counter(arr); lucky = [] for n in frequency: if n == frequency[n]: lucky.append(frequency[n]) return max(lucky) if len(lucky) > 0 else -1
find-lucky-integer-in-an-array
[Python3] using counter and max
Shiyinq
0
42
find lucky integer in an array
1,394
0.636
Easy
20,942
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1937040/Python-(Simple-Approach-and-Beginner-Friendly)
class Solution: def findLucky(self, arr: List[int]) -> int: count = Counter(arr) op = [-1] for i,n in reversed(count.items()): if i == n: op.append(i) return max(op)
find-lucky-integer-in-an-array
Python (Simple Approach and Beginner-Friendly)
vishvavariya
0
58
find lucky integer in an array
1,394
0.636
Easy
20,943
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1936339/Python-One-Line-or-Counter-or-Dictionary-or-Set
class Solution: def findLucky(self, arr): counter = {} for n in arr: counter[n] = counter.get(n, 0) + 1 lucky = {key for key, value in counter.items() if key == value} return max(lucky,default=-1)
find-lucky-integer-in-an-array
Python - One-Line | Counter | Dictionary | Set
domthedeveloper
0
60
find lucky integer in an array
1,394
0.636
Easy
20,944
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1936339/Python-One-Line-or-Counter-or-Dictionary-or-Set
class Solution: def findLucky(self, arr): counter = Counter(arr) lucky = {key for key, value in counter.items() if key == value} return max(lucky,default=-1)
find-lucky-integer-in-an-array
Python - One-Line | Counter | Dictionary | Set
domthedeveloper
0
60
find lucky integer in an array
1,394
0.636
Easy
20,945
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1936339/Python-One-Line-or-Counter-or-Dictionary-or-Set
class Solution: def findLucky(self, arr): return max({k for k,v in Counter(arr).items() if k==v}, default=-1)
find-lucky-integer-in-an-array
Python - One-Line | Counter | Dictionary | Set
domthedeveloper
0
60
find lucky integer in an array
1,394
0.636
Easy
20,946
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1896209/Python-easy-solution-for-beginners-using-sorting
class Solution: def findLucky(self, arr: List[int]) -> int: for i in sorted(set(arr), reverse=True): if arr.count(i) == i: return i return -1
find-lucky-integer-in-an-array
Python easy solution for beginners using sorting
alishak1999
0
69
find lucky integer in an array
1,394
0.636
Easy
20,947
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1862862/Python-solution
class Solution: def findLucky(self, arr: List[int]) -> int: from collections import Counter count=Counter(arr) for i in sorted(count,reverse=True): if count[i]==i: return i return -1
find-lucky-integer-in-an-array
Python solution
g0urav
0
25
find lucky integer in an array
1,394
0.636
Easy
20,948
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1862447/Python-Solution-using-Counter
class Solution: def findLucky(self, arr: List[int]) -> int: arrCount = Counter(arr) target = [key for key in arrCount if key == arrCount[key]] return max(target) if len(target) >= 1 else -1
find-lucky-integer-in-an-array
Python Solution using Counter
White_Frost1984
0
20
find lucky integer in an array
1,394
0.636
Easy
20,949
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1801230/Beginner-Friendly-or-Python
class Solution: def findLucky(self, arr: List[int]) -> int: nums =[] #Empty list for storing lucky integers for num in arr: if arr.count(num) == num: # Main condition nums.append(num) # Add to nums if len(nums) == 0: # If there is no lucky integar in arra...
find-lucky-integer-in-an-array
Beginner Friendly | Python
LittleMonster23
0
59
find lucky integer in an array
1,394
0.636
Easy
20,950
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1742997/Python-dollarolution
class Solution: def findLucky(self, arr: List[int]) -> int: for i in sorted(arr,reverse = True): if arr.count(i) == i: return i return -1
find-lucky-integer-in-an-array
Python $olution
AakRay
0
47
find lucky integer in an array
1,394
0.636
Easy
20,951
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1594976/Python-3-fast-easy-solution
class Solution: def findLucky(self, arr: List[int]) -> int: lucky = -1 counter = collections.Counter(arr) for num, freq in counter.items(): if num == freq and num > lucky: lucky = num return lucky
find-lucky-integer-in-an-array
Python 3 fast, easy solution
dereky4
0
106
find lucky integer in an array
1,394
0.636
Easy
20,952
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1544461/Easy-python-solution
class Solution: def findLucky(self, arr: List[int]) -> int: num_count = defaultdict(int) for num in arr: num_count[num] += 1 lucky_num = -1 for num, count in num_count.items(): if num == count: lucky_num = max(num, lucky_num) return luc...
find-lucky-integer-in-an-array
Easy python solution
akshaykumar19002
0
61
find lucky integer in an array
1,394
0.636
Easy
20,953
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1422478/O(N)-greater-O(1)-Space-Complexity-oror-Easy-to-Understand
class Solution: def findLucky(self, arr: List[int]) -> int: #lucky integer is an integer which has a frequency in the array #equal to its value #Approach 1 - Time Complexity - O(N) and Space Complexity - O(N) #We will create a dictionary #and store all the e...
find-lucky-integer-in-an-array
O(N) --> O(1) Space Complexity || Easy to Understand
aarushsharmaa
0
84
find lucky integer in an array
1,394
0.636
Easy
20,954
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1388354/Python3-Memory-Less-Than-97.54-Faster-Than-87.49
class Solution: def findLucky(self, arr: List[int]) -> int: from collections import Counter c = Counter(arr) mx = 0 for key, val in c.items(): if key == val: mx = max(mx, key) return mx if mx != 0 else -1
find-lucky-integer-in-an-array
Python3 Memory Less Than 97.54%, Faster Than 87.49%
Hejita
0
37
find lucky integer in an array
1,394
0.636
Easy
20,955
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1256813/python-easy-solution
class Solution: def findLucky(self, arr: List[int]) -> int: res = -1 dic = collections.Counter(arr) for item in dic: if item == dic[item]: if item > res: res = item return res
find-lucky-integer-in-an-array
python - easy solution
jayesh_kaushik
0
79
find lucky integer in an array
1,394
0.636
Easy
20,956
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/1004488/python-3-solution
class Solution: def findLucky(self, arr: List[int]) -> int: dic = {} high = -1 for nums in arr: if nums in dic: dic[nums] += 1 else: dic[nums] = 1 for nums in arr: if dic[nums] == nums ...
find-lucky-integer-in-an-array
python 3 solution
EH1
0
52
find lucky integer in an array
1,394
0.636
Easy
20,957
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/937180/Python3%3A-Using-Counter
class Solution: def findLucky(self, arr: List[int]) -> int: counter = collections.Counter(arr) largest = [] for num in counter: if num == counter[num]: largest.append(num) if largest: return max(largest) else: return -1
find-lucky-integer-in-an-array
Python3: Using Counter
MakeTeaNotWar
0
76
find lucky integer in an array
1,394
0.636
Easy
20,958
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/859651/Python3-freq-table
class Solution: def findLucky(self, arr: List[int]) -> int: freq = {} for x in arr: freq[x] = 1 + freq.get(x, 0) return max((x for x in arr if x == freq[x]), default=-1)
find-lucky-integer-in-an-array
[Python3] freq table
ye15
0
53
find lucky integer in an array
1,394
0.636
Easy
20,959
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/714519/Easy-Python-counter-and-non-counter-solution
class Solution: def findLucky(self, arr: List[int]) -> int: freq = {} maxVal = -1 for i in arr: if i in freq: freq[i] += 1 else: freq[i] = 1 for i in arr: if freq[i] == i: ...
find-lucky-integer-in-an-array
Easy Python counter and non-counter solution
alexr243
0
84
find lucky integer in an array
1,394
0.636
Easy
20,960
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/558683/python3-80-time-and-100-space
class Solution: def findLucky(self, arr: List[int]) -> int: viva = dict() ans = -1 for x in range(len(arr)): if arr[x] in viva: viva[arr[x]] += 1 else: viva[arr[x]] = 1 for key in sorted(list(viva.keys())): if key =...
find-lucky-integer-in-an-array
python3 80% time and 100% space
codexdelta
0
52
find lucky integer in an array
1,394
0.636
Easy
20,961
https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/554840/Python-3-Array-%2B-HashTable(Counting)
class Solution: def findLucky(self, arr: List[int]) -> int: ans = [0] * 501 res = -1 for i in range(len(arr)): ans[arr[i]] += 1 for i in range(1, 501): if ans[i] == i: res = max(res, i) return res
find-lucky-integer-in-an-array
[Python 3] Array + HashTable(Counting)
cr_496352127
0
43
find lucky integer in an array
1,394
0.636
Easy
20,962
https://leetcode.com/problems/count-number-of-teams/discuss/1465532/Python-or-O(n2)-or-Slow-but-very-easy-to-understand-or-Explanation
class Solution: def numTeams(self, rating: List[int]) -> int: dp = [[1, 0, 0] for i in range(len(rating))] for i in range(1, len(rating)): for j in range(i): if rating[i] > rating[j]: dp[i][1] += dp[j][0] dp[i][2] ...
count-number-of-teams
Python | O(n^2) | Slow but very easy to understand | Explanation
detective_dp
5
595
count number of teams
1,395
0.68
Medium
20,963
https://leetcode.com/problems/count-number-of-teams/discuss/555469/Python-O(n2)-sol-by-sliding-range-w-Diagram
class Solution: def numTeams(self, rating: List[int]) -> int: r, size = rating, len( rating ) # compute statistics of sliding range left_smaller = [ sum( r[i] < r[j] for i in range(0,j) ) for j in range(size) ] right_bigger = [ sum( r[j] < r[k] for k in range(j+1, size) ) for j in...
count-number-of-teams
Python O(n^2) sol by sliding range [w/ Diagram]
brianchiang_tw
4
583
count number of teams
1,395
0.68
Medium
20,964
https://leetcode.com/problems/count-number-of-teams/discuss/555469/Python-O(n2)-sol-by-sliding-range-w-Diagram
class Solution: def numTeams(self, rating: List[int]) -> int: r, size = rating, len( rating ) # compute statistics of sliding range left_smaller = [ sum( r[i] < r[j] for i in range(0,j) ) for j in range(size) ] right_bigger = [ sum( r[j] < r[k] for k in range(j+1, size) ) for j in...
count-number-of-teams
Python O(n^2) sol by sliding range [w/ Diagram]
brianchiang_tw
4
583
count number of teams
1,395
0.68
Medium
20,965
https://leetcode.com/problems/count-number-of-teams/discuss/1079864/Python3-dp
class Solution: def numTeams(self, rating: List[int]) -> int: ans = 0 seen = [[0]*2 for _ in rating] for i in range(len(rating)): for ii in range(i): if rating[ii] < rating[i]: ans += seen[ii][0] seen[i][0] += 1 ...
count-number-of-teams
[Python3] dp
ye15
1
309
count number of teams
1,395
0.68
Medium
20,966
https://leetcode.com/problems/count-number-of-teams/discuss/2794657/DP-python-solution-O(n2)
class Solution: def numTeams(self, rating: List[int]) -> int: N = len(rating) dp = [[0] * N for _ in range(3)] for i in range(N): dp[0][i] = 1 for i in range(1, 3): for j in range(i, N): for k in range(i - 1, j): i...
count-number-of-teams
DP / python solution / O(n^2)
Lara_Craft
0
8
count number of teams
1,395
0.68
Medium
20,967
https://leetcode.com/problems/count-number-of-teams/discuss/1816368/Pyhton-or-O(n2)-or-Easy-solution
class Solution: def getValueCount(self,value,rating, isSmallerCount = False): count = 0 for t in rating: if isSmallerCount: if t > value: count += 1 else: if t < value: count += 1 return count ...
count-number-of-teams
Pyhton | O(n^2) | Easy solution
iamamiya
0
188
count number of teams
1,395
0.68
Medium
20,968
https://leetcode.com/problems/count-number-of-teams/discuss/1588488/Python3-O(n3)-and-O(n2)-solution
class Solution: def numTeams(self, rating: List[int]) -> int: res = 0 for i in range(len(rating) - 2): for j in range(i + 1, len(rating) - 1): for k in range(j + 1, len(rating)): if rating[i] > rating[j] and rating[j] > rating[k] or rating[i] < rating[...
count-number-of-teams
[Python3] O(n^3) and O(n^2) solution
maosipov11
0
156
count number of teams
1,395
0.68
Medium
20,969
https://leetcode.com/problems/count-number-of-teams/discuss/695427/Python-3-C-Brute-Force
class Solution: def numTeams(self, rating: List[int]) -> int: count = 0 for i in range(len(rating)): for j in range(i+1,len(rating)): for k in range(j+1,len(rating)): if((rating[i]>rating[j] and rating[j]>rating[k]) or (rating[i]<rating[j] and...
count-number-of-teams
[Python 3 / C] Brute Force
abhijeetmallick29
0
95
count number of teams
1,395
0.68
Medium
20,970
https://leetcode.com/problems/count-number-of-teams/discuss/658043/python3-Brute-Force-solution-memory-100
class Solution: def numTeams(self, rating: List[int]) -> int: if len(rating) < 3: return 0 else: count = 0 for i in range(len(rating)-2): arr = [] arr.append(rating[i]) for j in range(i+1,len(rating)-1): ...
count-number-of-teams
python3 Brute Force solution, memory 100%
zharfanf
0
139
count number of teams
1,395
0.68
Medium
20,971
https://leetcode.com/problems/count-number-of-teams/discuss/591389/Intuitive-recursive-approach
class Solution: def numTeams(self, rating: List[int]) -> int: teams = [0] def up(n1, n2): return n2 > n1 def down(n1, n2): return n2 < n1 def search_team(team, np=0, op=up): for i in range(np, len(rating)): ...
count-number-of-teams
Intuitive recursive approach
puremonkey2001
0
146
count number of teams
1,395
0.68
Medium
20,972
https://leetcode.com/problems/find-all-good-strings/discuss/1133347/Python3-dp-and-kmp-...-finally
class Solution: def findGoodStrings(self, n: int, s1: str, s2: str, evil: str) -> int: lps = [0] k = 0 for i in range(1, len(evil)): while k and evil[k] != evil[i]: k = lps[k-1] if evil[k] == evil[i]: k += 1 lps.append(k) @cache ...
find-all-good-strings
[Python3] dp & kmp ... finally
ye15
3
351
find all good strings
1,397
0.422
Hard
20,973
https://leetcode.com/problems/find-all-good-strings/discuss/2834604/Faster-and-less-memory-than-all-other-solutions
class Solution: def findGoodStrings(self, n: int, s1: str, s2: str, evil: str) -> int: p=10**9+7 ord_a=ord('a') l=len(evil) dup=[] for i in range(1, l): if evil[i:]==evil[:l-i]: dup.append(i) lend=len(dup) def count(s): ...
find-all-good-strings
Faster and less memory than all other solutions
mbeceanu
0
5
find all good strings
1,397
0.422
Hard
20,974
https://leetcode.com/problems/count-largest-group/discuss/660765/Python-DP-O(N)-99100
class Solution: def countLargestGroup(self, n: int) -> int: dp = {0: 0} counts = [0] * (4 * 9) for i in range(1, n + 1): quotient, reminder = divmod(i, 10) dp[i] = reminder + dp[quotient] counts[dp[i] - 1] += 1 return counts.count(max(counts))
count-largest-group
Python DP O(N) 99%/100%
xshoan
43
2,000
count largest group
1,399
0.672
Easy
20,975
https://leetcode.com/problems/count-largest-group/discuss/611971/Python-easy-to-understand
class Solution(object): def countLargestGroup(self, n): """ :type n: int :rtype: int """ res = [] for i in range(1, n+1): res.append(sum(int(x) for x in str(i))) c = collections.Counter(res) x = [i for i in c.values() if...
count-largest-group
Python easy to understand
goodfine1210
5
533
count largest group
1,399
0.672
Easy
20,976
https://leetcode.com/problems/count-largest-group/discuss/1817885/Python-Easy-Solution
class Solution: def countLargestGroup(self, n: int) -> int: def val(): return 0 dic = defaultdict(val) for i in range(1,n+1): st = str(i) ans = 0 for j in st: ans += int(j) dic[ans] += 1 m...
count-largest-group
Python Easy Solution
MS1301
1
79
count largest group
1,399
0.672
Easy
20,977
https://leetcode.com/problems/count-largest-group/discuss/1195100/Python-Line-by-Line-Explanations-with-comments(-Fast-and-easy)
class Solution: def countLargestGroup(self, n: int) -> int: #Function to get sum of digits def get_sum(value): res = 0 while value: res += (value % 10) value //= 10 return res #Dictionary to group values with same sum eg -...
count-largest-group
Python Line by Line Explanations with comments( Fast and easy)
iamkshitij77
1
213
count largest group
1,399
0.672
Easy
20,978
https://leetcode.com/problems/count-largest-group/discuss/2823584/Simple-python-solution-using-map
class Solution: def countLargestGroup(self, n: int) -> int: def sum_digits(num): sum1 = 0 while num>0: sum1+=num%10 num//=10 return sum1 map1 = {} maxi = 0 count = 0 for i in range(1, n+1): s = s...
count-largest-group
Simple python solution using map
Rajeev_varma008
0
4
count largest group
1,399
0.672
Easy
20,979
https://leetcode.com/problems/count-largest-group/discuss/2307609/Python3-simple-solution
class Solution: def countLargestGroup(self, n: int) -> int: arr = [] for i in range(1, n + 1): x = i t = 0 while x > 0: t = t + (x % 10) x = x // 10 arr.append(t) retur...
count-largest-group
Python3 simple solution
mediocre-coder
0
35
count largest group
1,399
0.672
Easy
20,980
https://leetcode.com/problems/count-largest-group/discuss/2114233/Easy-Python-code
class Solution: def countLargestGroup(self, n: int) -> int: dic = {} for i in range(1,n+1): sum1 = 0 for num in str(i): sum1 = sum1 + int(num) if sum1 in dic: dic[sum1] += 1 else: dic[sum1] = 1 ...
count-largest-group
Easy Python code
prernaarora221
0
94
count largest group
1,399
0.672
Easy
20,981
https://leetcode.com/problems/count-largest-group/discuss/2022156/Python-Clean-and-Simple!
class Solution: def countLargestGroup(self, n): counts = Counter() for i in range(1,n+1): digitSum = sum(int(c) for c in str(i)) counts[digitSum] += 1 maxCount = max(counts.values()) return sum(count == maxCount for count in counts.values())
count-largest-group
Python - Clean and Simple!
domthedeveloper
0
106
count largest group
1,399
0.672
Easy
20,982
https://leetcode.com/problems/count-largest-group/discuss/1875539/Python-(Simple-Approach-and-Beginner-Friendly)
class Solution: def countLargestGroup(self, n: int) -> int: dict = {} output = 0 for i in range(1, n+1): count = 0 if len(str(i)) == 1: if str(i) not in dict: dict[i] = 1 else: dict[i]+=1 ...
count-largest-group
Python (Simple Approach and Beginner-Friendly)
vishvavariya
0
96
count largest group
1,399
0.672
Easy
20,983
https://leetcode.com/problems/count-largest-group/discuss/1850004/3-Lines-Python-Solution-oror-60-Faster-oror-Memory-less-than-85
class Solution: def countLargestGroup(self, n: int) -> int: ans=dict.fromkeys([i for i in range(1,37)], 0) for i in range(1,n+1): s=sum([int(x) for x in str(i)]) ; ans[s]+=1 return max(Counter([y for x,y in ans.items()]).items(), key=itemgetter(0))[1]
count-largest-group
3-Lines Python Solution || 60% Faster || Memory less than 85%
Taha-C
0
86
count largest group
1,399
0.672
Easy
20,984
https://leetcode.com/problems/count-largest-group/discuss/1850004/3-Lines-Python-Solution-oror-60-Faster-oror-Memory-less-than-85
class Solution: def countLargestGroup(self, n: int) -> int: ans=dict.fromkeys([i for i in range(1,37)], 0) for i in range(1,n+1): ans[sum([int(x) for x in str(i)])]+=1 return sum(1 for x in ans.values() if x==max(ans.values()))
count-largest-group
3-Lines Python Solution || 60% Faster || Memory less than 85%
Taha-C
0
86
count largest group
1,399
0.672
Easy
20,985
https://leetcode.com/problems/count-largest-group/discuss/1850004/3-Lines-Python-Solution-oror-60-Faster-oror-Memory-less-than-85
class Solution: def countLargestGroup(self, n: int) -> int: ans=[] for i in range(1,n+1): ans.append(sum(int(x) for x in str(i))) C=Counter(ans).values() ; mx=max(C) return sum([1 for x in C if x==mx])
count-largest-group
3-Lines Python Solution || 60% Faster || Memory less than 85%
Taha-C
0
86
count largest group
1,399
0.672
Easy
20,986
https://leetcode.com/problems/count-largest-group/discuss/1799926/Python3-accepted-solution-(using-defaultdict)
class Solution: from collections import defaultdict def countLargestGroup(self, n: int) -> int: memo = defaultdict(list) for i in range(1,n+1): memo[sum([int(i) for i in str(i)])].append(i) li = sorted([memo[i] for i in memo.keys()],key=len) return len([j for j in li ...
count-largest-group
Python3 accepted solution (using defaultdict)
sreeleetcode19
0
20
count largest group
1,399
0.672
Easy
20,987
https://leetcode.com/problems/count-largest-group/discuss/1743036/Python-dollarolution-(mem-use%3A-less-than-100)
class Solution: def countLargestGroup(self, n: int) -> int: d, count, m = {}, 0, 0 for i in range(1,n+1): c, j = 0, i while j != 0: c += j%10 j //= 10 if c not in d: d[c] = 1 else: d[c] +=...
count-largest-group
Python $olution (mem use: less than 100%)
AakRay
0
71
count largest group
1,399
0.672
Easy
20,988
https://leetcode.com/problems/count-largest-group/discuss/1368137/Python3-solution
class Solution: def countLargestGroup(self, n: int) -> int: count = 0 d = {} # we need a dictionary to store the values def sum_digits(n): n_sum = 0 while n > 0: r = n % 10 n_sum += r n //= 10 return n_sum ...
count-largest-group
Python3 solution
FlorinnC1
0
94
count largest group
1,399
0.672
Easy
20,989
https://leetcode.com/problems/count-largest-group/discuss/1158988/python-with-comments
class Solution: def countLargestGroup(self, n: int) -> int: # calculating sum of digits of given num def sod(num): dsum = 0 while num > 0: num, mod = divmod(num, 10) dsum += mod return dsum res = 0 ...
count-largest-group
python with comments
keewook2
0
119
count largest group
1,399
0.672
Easy
20,990
https://leetcode.com/problems/count-largest-group/discuss/1142188/Python-Solution-100-space-optimize
class Solution: def countLargestGroup(self, n: int) -> int: arr = [0] * (10**4+1) for x in range(1,n+1): temp = x s = 0 while temp: s+= temp%10 temp //= 10 arr[s] += 1 return arr.count(max(arr))
count-largest-group
Python Solution 100% space optimize
Sanjaychandak95
0
125
count largest group
1,399
0.672
Easy
20,991
https://leetcode.com/problems/count-largest-group/discuss/1067026/Python3-simple-solution-using-two-different-approaches
class Solution: def countLargestGroup(self, n: int) -> int: d = {} for i in range(1,n+1): x = sum(list(map(int, list(str(i))))) d[x] = d.get(x,[]) + [i] l = sorted(d.values(), key= lambda x:len(x), reverse = True) max = len(l[0]) count = 0 for ...
count-largest-group
Python3 simple solution using two different approaches
EklavyaJoshi
0
74
count largest group
1,399
0.672
Easy
20,992
https://leetcode.com/problems/count-largest-group/discuss/1067026/Python3-simple-solution-using-two-different-approaches
class Solution: def countLargestGroup(self, n: int) -> int: d = {} for i in range(1,n+1): x = sum(list(map(int, list(str(i))))) d[x] = d.get(x,[]) + [i] max_len = 0 count = 1 for i in d.values(): if len(i) == max_len: count ...
count-largest-group
Python3 simple solution using two different approaches
EklavyaJoshi
0
74
count largest group
1,399
0.672
Easy
20,993
https://leetcode.com/problems/count-largest-group/discuss/859672/Python3-frequency-table
class Solution: def countLargestGroup(self, n: int) -> int: freq = {} for x in range(1, n+1): key = sum(int(d) for d in str(x)) freq[key] = 1 + freq.get(key, 0) vals = list(freq.values()) return vals.count(max(vals))
count-largest-group
[Python3] frequency table
ye15
0
93
count largest group
1,399
0.672
Easy
20,994
https://leetcode.com/problems/construct-k-palindrome-strings/discuss/1806250/Python-Solution
class Solution: def canConstruct(self, s: str, k: int) -> bool: if k > len(s): return False dic = {} for i in s: if i not in dic: dic[i] = 1 else: dic[i] += 1 c = 0 for i in dic.values(): ...
construct-k-palindrome-strings
Python Solution
MS1301
1
91
construct k palindrome strings
1,400
0.632
Medium
20,995
https://leetcode.com/problems/construct-k-palindrome-strings/discuss/1079932/Python3-freq-table
class Solution: def canConstruct(self, s: str, k: int) -> bool: freq = {} for c in s: freq[c] = 1 + freq.get(c, 0) return sum(freq[c]&amp;1 for c in freq) <= k <= len(s)
construct-k-palindrome-strings
[Python3] freq table
ye15
1
97
construct k palindrome strings
1,400
0.632
Medium
20,996
https://leetcode.com/problems/construct-k-palindrome-strings/discuss/2814817/C%2B%2B-Python3-Solution-or-XOR
class Solution: def canConstruct(self, S, K): return bin(reduce(operator.xor, map(lambda x: 1 << (ord(x) - 97), S))).count('1') <= K <= len(S)
construct-k-palindrome-strings
✔ [C++ / Python3] Solution | XOR
satyam2001
0
3
construct k palindrome strings
1,400
0.632
Medium
20,997
https://leetcode.com/problems/construct-k-palindrome-strings/discuss/2761235/Python-3-Solution
class Solution: def canConstruct(self, s: str, k: int) -> bool: D = defaultdict(int) for x in s: D[x] = (D[x] + 1)%2 if sum(list(D.values())) <= k and len(s) >= k: return True return False
construct-k-palindrome-strings
Python 3 Solution
mati44
0
4
construct k palindrome strings
1,400
0.632
Medium
20,998
https://leetcode.com/problems/construct-k-palindrome-strings/discuss/2413366/easy-python-solution
class Solution: def canConstruct(self, s: str, k: int) -> bool: char = [i for i in s] if len(char) < k : return False else : char_dic, odd_count = {}, 0 for ch in set(char) : char_dic[ch] = char.count(ch) if (char.count(...
construct-k-palindrome-strings
easy python solution
sghorai
0
55
construct k palindrome strings
1,400
0.632
Medium
20,999