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/all-paths-from-source-to-target/discuss/2225609/Python-3%3A-DFS-and-BFS
class Solution: def allPathsSourceTarget(self, graph): stack = [] for ii in range(len(graph[0])): stack.append((graph[0][ii],[0,graph[0][ii]])) final = [] while stack: end, road = stack.pop() if end == l...
all-paths-from-source-to-target
Python 3: DFS & BFS
SetsunaOgiso
0
23
all paths from source to target
797
0.815
Medium
13,000
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/2022607/Fast-DFS-Solution
class Solution: def solve(self, current,output,n, graph): if current==n: self.ans.append(list(output)) return for i in range(len(graph[current])): output.append(graph[current][i]) self.solve(graph[current][i],output,n, graph) output.pop() ...
all-paths-from-source-to-target
Fast DFS Solution
dbansal18
0
28
all paths from source to target
797
0.815
Medium
13,001
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1872285/Python3-Traversal-with-2D-linked-list
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: self.res = [] # Keep track of all the paths during recursion path = [] self.traverse(graph, 0, path) return self.res def traverse(self, graph, s, path): path.append(s) ...
all-paths-from-source-to-target
[Python3] Traversal with 2D linked-list
leqinancy
0
12
all paths from source to target
797
0.815
Medium
13,002
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1858003/Python-Solution-oror-Backtracking
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: def pathtrack(node,path,ans,graph,l): if node == [] or path[-1] == l-1: if path[-1] != l-1: path.pop(-1) return ans.append(path) ...
all-paths-from-source-to-target
Python Solution || Backtracking
MS1301
0
49
all paths from source to target
797
0.815
Medium
13,003
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1815375/Python-Backtracking
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: n = len(graph) def backtrack(result, curr=0, nodesInPath=[0]): if curr == n - 1: result.append(nodesInPath[:]) if not graph[curr]: return ...
all-paths-from-source-to-target
Python Backtracking
Rush_P
0
41
all paths from source to target
797
0.815
Medium
13,004
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1805112/Python-or-why-use-deque-instead-of-List-in-Backtracking
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: def backtrack(graph, s, p): # the path should be a nonlocal variable nonlocal path if not graph: return n = len(graph) ...
all-paths-from-source-to-target
Python | why use deque instead of List in Backtracking?
Fayeyf
0
34
all paths from source to target
797
0.815
Medium
13,005
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1746645/108-ms-faster-than-61.22-Memory-Usage%3A-15.7-MB-less-than-51.25-using-python3-and-backtracking
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: self.res = [] self.n = len(graph) self.vis = [False for i in range(self.n)] def solve(path,index): if(path[-1] == self.n-1): self.res.append(path) return if(not graph[index]): if(path[-1] ==self.n - 1):...
all-paths-from-source-to-target
108 ms, faster than 61.22% Memory Usage: 15.7 MB, less than 51.25% using python3 and backtracking
jagdishpawar8105
0
60
all paths from source to target
797
0.815
Medium
13,006
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1699730/Python-Easy-Solution
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: out = [] def findPath(i=0, l=[]): l.append(i) if i == len(graph)-1: out.append(l) for ele in graph[i]: findPath(ele, l.copy()) findPath() return out
all-paths-from-source-to-target
Python Easy Solution
dhnam2234
0
66
all paths from source to target
797
0.815
Medium
13,007
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1692734/797-All-paths-From-Source-to-Target-via-Backtracking
class Solution: def allPathsSourceTarget(self, graph): result = []; path = [0] self.dfs(graph, result, path, 0) return result def dfs(self, graph, result, path, start): if start == len(graph) - 1: result.append(path[:]) return for node in graph[start]: ### search space path.append(node) ...
all-paths-from-source-to-target
797 All paths From Source to Target via Backtracking
zwang198
0
267
all paths from source to target
797
0.815
Medium
13,008
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1692734/797-All-paths-From-Source-to-Target-via-Backtracking
class Solution: def allPathsSourceTarget(self, graph): result = []; path = [] self.dfs(graph, result, path, 0) return result def dfs(self, graph, result, path, start): path.append(start) if start == len(graph) - 1: result.append(path[:]) path.pop() return for node in graph[start]: ### ...
all-paths-from-source-to-target
797 All paths From Source to Target via Backtracking
zwang198
0
267
all paths from source to target
797
0.815
Medium
13,009
https://leetcode.com/problems/all-paths-from-source-to-target/discuss/1684571/python3-slow-but-easy-BFS-solution-w-explanation
class Solution: def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]: total = [[0]] ans = [] target = len(graph) - 1 while total: # start BFS itr = total.pop(0) last = itr[-1] possible = graph[last] if not possible:...
all-paths-from-source-to-target
python3 slow but easy BFS solution w explanation
752937603
0
48
all paths from source to target
797
0.815
Medium
13,010
https://leetcode.com/problems/smallest-rotation-with-highest-score/discuss/1307760/Python3-difference-array
class Solution: def bestRotation(self, nums: List[int]) -> int: diff = [0]*(len(nums) + 1) for i, x in enumerate(nums): diff[i+1] += 1 if x <= i: diff[0] += 1 diff[(i-x)%len(nums) + 1] -= 1 ans = prefix = 0 mx = -inf for i, x in...
smallest-rotation-with-highest-score
[Python3] difference array
ye15
0
137
smallest rotation with highest score
798
0.498
Hard
13,011
https://leetcode.com/problems/smallest-rotation-with-highest-score/discuss/1307760/Python3-difference-array
class Solution: def bestRotation(self, nums: List[int]) -> int: diff = [1] * len(nums) for i, x in enumerate(nums): diff[(i-x+1) % len(nums)] -= 1 prefix = list(accumulate(diff)) return prefix.index(max(prefix))
smallest-rotation-with-highest-score
[Python3] difference array
ye15
0
137
smallest rotation with highest score
798
0.498
Hard
13,012
https://leetcode.com/problems/champagne-tower/discuss/1818232/Python-Easy-Solution-or-95-Faster-or-Dynamic-Programming
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: dp = [[0 for _ in range(x)] for x in range(1, query_row + 2)] dp[0][0] = poured for i in range(query_row): for j in range(len(dp[i])): temp = (dp[i][j] - 1) ...
champagne-tower
✔️ Python Easy Solution | 95% Faster | Dynamic Programming
pniraj657
24
1,300
champagne tower
799
0.513
Medium
13,013
https://leetcode.com/problems/champagne-tower/discuss/1819005/Python-Detailed-explanation-or-faster-than-92.23-or-Memory-less-than-95.15
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: pyramid = {k-1:[0] * k for k in range(1, 101)} pyramid[0][0] = poured for row in range(1, query_row+1): T = True for c in range(row): val = (pyramid[row-1...
champagne-tower
[Python] Detailed explanation | faster than 92.23% | Memory less than 95.15%
zouhair11elhadi
4
123
champagne tower
799
0.513
Medium
13,014
https://leetcode.com/problems/champagne-tower/discuss/1817816/Python-Simple-Python-Solution-Using-Dynamic-Programming
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: dp = [[0]*x for x in range(1,102)] dp[0][0] = poured for row in range(query_row + 1): for col in range(row + 1): mid_pour = (dp[row][col] - 1.0) / 2.0 if mid_pour > 0: dp[row+1][col] = dp[row+...
champagne-tower
[ Python ] ✔✔ Simple Python Solution Using Dynamic Programming 🔥✌
ASHOK_KUMAR_MEGHVANSHI
3
375
champagne tower
799
0.513
Medium
13,015
https://leetcode.com/problems/champagne-tower/discuss/1817737/Simulation-with-flag
class Solution: def champagneTower(self, poured: int, r: int, c: int) -> float: dp = [[0] * i for i in range(1, 102)] dp[0][0] = poured for i in range(100): go_to_next_level = False #set a flag to judge if you go to next level or not for j in range(i + 1): ...
champagne-tower
Simulation with flag
kryuki
2
32
champagne tower
799
0.513
Medium
13,016
https://leetcode.com/problems/champagne-tower/discuss/986513/Python3-dp-(top-down-and-bottom-up)
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: @lru_cache(None) def fn(i, j): """Return wine poured into glass (i, j).""" if i == j == 0: return poured # boundary condition if j < 0 or j > i: return 0 # b...
champagne-tower
[Python3] dp (top-down & bottom-up)
ye15
2
162
champagne tower
799
0.513
Medium
13,017
https://leetcode.com/problems/champagne-tower/discuss/986513/Python3-dp-(top-down-and-bottom-up)
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: dp = [poured] + query_row*[0] for i in range(1, query_row+1): for j in reversed(range(i+1)): dp[j] = max(0, dp[j]-1)/2 + (j>0)*max(0, dp[j-1]-1)/2 return min(1, dp[...
champagne-tower
[Python3] dp (top-down & bottom-up)
ye15
2
162
champagne tower
799
0.513
Medium
13,018
https://leetcode.com/problems/champagne-tower/discuss/1819960/Python-Easy-To-Understand-With-Explanation.
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: # Create the levels with exact number of elements in each level # 1,2,3,4,5,----- levels = [[0]*i for i in range(1,query_row+2)] # Update the first level with the poured wine. l...
champagne-tower
Python Easy To Understand With Explanation.
H1ccup
1
31
champagne tower
799
0.513
Medium
13,019
https://leetcode.com/problems/champagne-tower/discuss/1818236/Recursion-with-memoization-Simple-approach-Easy-to-Understand-Dynamic-programming-Python
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: def solve(val, r, g,dp): if r==0 and g==0: return val if g<0 or g>r: return 0 if (r,g) in dp: return dp[(r,g)] lef...
champagne-tower
Recursion with memoization , Simple approach , Easy to Understand , Dynamic programming , Python
user8744WJ
1
102
champagne tower
799
0.513
Medium
13,020
https://leetcode.com/problems/champagne-tower/discuss/2804556/Python-recursion
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: @cache def helper(i, j): if i == 0 and j == 0: return poured left, right = 0, 0 if j > 0: left = helper(i - 1, j - 1) ...
champagne-tower
Python, recursion
yiming999
0
1
champagne tower
799
0.513
Medium
13,021
https://leetcode.com/problems/champagne-tower/discuss/1820912/Python-Solution
class Solution: def champagneTower(self, poured, query_row, query_glass): glasses = [poured] for _ in range(query_row): temp = [0] * (len(glasses) + 1) for i in range(len(glasses)): pour = (glasses[i] - 1) / 2 if pour > 0: ...
champagne-tower
Python Solution
pradeep288
0
20
champagne tower
799
0.513
Medium
13,022
https://leetcode.com/problems/champagne-tower/discuss/1820120/Python-DP-97.5
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: row, row_count = [poured], 0 while row_count < query_row: prev = 0 for i in range(len(row)): if row[i] > 1: prev, row[i] = ro...
champagne-tower
Python DP 97.5%
Rush_P
0
17
champagne tower
799
0.513
Medium
13,023
https://leetcode.com/problems/champagne-tower/discuss/1818956/Help-needed-I-don't-know-where-went-wrong-when-submiting-the-code
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: return min(self.getAmountPouredIntoThisGlass(poured, query_row, query_glass), 1) def getAmountPouredIntoThisGlass(self, poured, query_row, query_glass, d=dict())-> float: if query_row == 0: ...
champagne-tower
Help needed, I don't know where went wrong when submiting the code
hclbeatyou
0
14
champagne tower
799
0.513
Medium
13,024
https://leetcode.com/problems/champagne-tower/discuss/1818714/Python-or-DP-2D-or-Clean-and-easy
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: dp = [[0 for _ in range(x)] for x in range(1, query_row + 2)] dp[0][0] = poured for i in range(query_row): for j in range(len(dp[i])): temp = (dp[i][j] - 1) ...
champagne-tower
Python | DP-2D | Clean and easy
sravyan
0
39
champagne tower
799
0.513
Medium
13,025
https://leetcode.com/problems/champagne-tower/discuss/1818510/Python3-Easy
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: arr = [[0 for i in range(101)] for j in range(101)] arr[0][0] = poured for i in range(100): for j in range(i+1): if arr[i][j] > 1: arr[i+...
champagne-tower
Python3 Easy
rishabhmanu
0
22
champagne tower
799
0.513
Medium
13,026
https://leetcode.com/problems/champagne-tower/discuss/1818463/Simple-Python3-Solution
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: dp = [[0 for _ in range(x)] for x in range(1, query_row + 2)] dp[0][0] = poured for i in range(query_row): for j in range(len(dp[i])): temp = (dp[i][j] - 1) ...
champagne-tower
Simple Python3 Solution
user6774u
0
22
champagne tower
799
0.513
Medium
13,027
https://leetcode.com/problems/champagne-tower/discuss/1817671/Fast-PHP-solution-(also-Python3-and-JS)-w-explanation
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: # Start out with 1 glass containing all the champagne. row = 0 rows = [[poured], 1] prev = 0 while(True): spilled = False for i,glass in ...
champagne-tower
Fast PHP solution (also Python3 and JS) w/ explanation
crankyinmv
0
36
champagne tower
799
0.513
Medium
13,028
https://leetcode.com/problems/champagne-tower/discuss/1275558/python-solution-or
class Solution: def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: dp =[ [0]*row for row in range(1,100+2) ] dp[0][0] = poured for i in range(query_row+1): for j in range(i+1):# calc...
champagne-tower
python solution |
chikushen99
0
113
champagne tower
799
0.513
Medium
13,029
https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/discuss/932390/Python3-two-counters
class Solution: def minSwap(self, A: List[int], B: List[int]) -> int: ans = sm = lg = mx = 0 for x, y in zip(A, B): if mx < min(x, y): # prev max < current min ans += min(sm, lg) # update answer &amp; reset sm = lg = 0 mx = max(x, y) ...
minimum-swaps-to-make-sequences-increasing
[Python3] two counters
ye15
8
237
minimum swaps to make sequences increasing
801
0.393
Hard
13,030
https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/discuss/2675067/Python3-DP-Solution-O(n)-Time
class Solution: def minSwap(self, nums1: List[int], nums2: List[int]) -> int: dp = [[-1]*2 for i in range(len(nums1))] def solve(prev1, prev2, i, swaped): if i >= len(nums1): return 0 if dp[i][swaped] != -1: return dp[i][swaped] a...
minimum-swaps-to-make-sequences-increasing
✅ [Python3] DP Solution O(n) Time
samirpaul1
2
198
minimum swaps to make sequences increasing
801
0.393
Hard
13,031
https://leetcode.com/problems/find-eventual-safe-states/discuss/1317749/Python-DFS-Easy
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: n=len(graph) status=[0]*(n) res=[] def dfs(i):# this function will check is there any loop, cycle and i is a part of that loop,cycle if status[i]=="visited": #if this node is alrea...
find-eventual-safe-states
Python-DFS-Easy
manmohan1105
9
575
find eventual safe states
802
0.553
Medium
13,032
https://leetcode.com/problems/find-eventual-safe-states/discuss/2548451/Python-Elegant-and-Short-or-O(V-%2B-E)-or-Three-color-DFS
class Solution: """ Time: O(V + E) Memory: O(V) """ WHITE = 0 GRAY = 1 BLACK = 2 def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: def dfs(u: int) -> bool: if color[u] == self.GRAY: return True if color[u] == self.BLACK: return False color[u] = self.GRAY for v in grap...
find-eventual-safe-states
Python Elegant & Short | O(V + E) | Three-color DFS
Kyrylo-Ktl
3
160
find eventual safe states
802
0.553
Medium
13,033
https://leetcode.com/problems/find-eventual-safe-states/discuss/2829279/Python3-Solution-or-DFS-or-O(n)
class Solution: def eventualSafeNodes(self, graph): N = len(graph) dp = [-1] * N def dfs(x): if dp[x] != -1: return dp[x] dp[x] = 0 for i in graph[x]: if dfs(i) == 0: return 0 dp[x] = 1 return 1 ...
find-eventual-safe-states
✔ Python3 Solution | DFS | O(n)
satyam2001
2
21
find eventual safe states
802
0.553
Medium
13,034
https://leetcode.com/problems/find-eventual-safe-states/discuss/1653036/Python3-Solution-with-using-topological-sorting
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: g = collections.defaultdict(list) indegree = collections.defaultdict(int) for v, neigbs in enumerate(graph): for neigb in neigbs: g[neigb].append(v) indegree...
find-eventual-safe-states
[Python3] Solution with using topological sorting
maosipov11
2
95
find eventual safe states
802
0.553
Medium
13,035
https://leetcode.com/problems/find-eventual-safe-states/discuss/1604866/Python3-Kahn's-Algorithm-(count-number-of-reach-times)-with-BFS
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: """ 1. find all nodes that do not have outgoing edges -> terminal node 2. reverse all edges 3. from each terminal node, do BFS/DFS, the node we are reaching at the end are safe nodes """ ...
find-eventual-safe-states
[Python3] Kahn's Algorithm (count number of reach times) with BFS
nick19981122
2
164
find eventual safe states
802
0.553
Medium
13,036
https://leetcode.com/problems/find-eventual-safe-states/discuss/2705693/DFS-solution-using-cycle-detection-in-python
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: def check_cycle(node,graph,visited): if visited[node]==2: return True visited[node]=2 for neighbour in graph[node]: if visited[neighbour]!=1: ...
find-eventual-safe-states
DFS solution using cycle detection in python
shashank_2000
1
10
find eventual safe states
802
0.553
Medium
13,037
https://leetcode.com/problems/find-eventual-safe-states/discuss/2024860/Python-easy-to-read-and-understand-or-dfs-(cycle-detection)
class Solution: def isCycle(self, graph, node, visit): if visit[node] == 2: return True visit[node] = 2 for nei in graph[node]: if visit[nei] != 1: if self.isCycle(graph, nei, visit): return True visit[node] = 1 retu...
find-eventual-safe-states
Python easy to read and understand | dfs (cycle detection)
sanial2001
1
116
find eventual safe states
802
0.553
Medium
13,038
https://leetcode.com/problems/find-eventual-safe-states/discuss/932606/Python3-repeatedly-removing-terminals
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: ans, out, inn = [], [], [[] for _ in graph] # reversed graph for i, x in enumerate(graph): if not x: ans.append(i) # safe states out.append(len(x)) # out degree for xx in x: inn[...
find-eventual-safe-states
[Python3] repeatedly removing terminals
ye15
1
67
find eventual safe states
802
0.553
Medium
13,039
https://leetcode.com/problems/find-eventual-safe-states/discuss/424804/simple-DFS-python-solution-with-explanation-faster-than-93
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: N = len(graph) T = set([n for n in range(N) if not graph[n]]) V = set() def dfs(node,visited): if node in T: return True if node in V or node in visited: ...
find-eventual-safe-states
simple DFS python solution with explanation faster than 93%
Maple177
1
185
find eventual safe states
802
0.553
Medium
13,040
https://leetcode.com/problems/find-eventual-safe-states/discuss/2824574/Python
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: n = len(graph) safe ={} res =[] def dfs(i): if i in safe: return safe[i] safe[i] = False for nei in graph[i]: if not dfs(nei): ...
find-eventual-safe-states
Python
Sangeeth_psk
0
2
find eventual safe states
802
0.553
Medium
13,041
https://leetcode.com/problems/find-eventual-safe-states/discuss/2713370/python-solution-using-topological-sort
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: n=len(graph) indegree=[0]*(n) adj=[[]for _ in range(n)] for u in range(n): for v in graph[u]: adj[v].append(u) indegree[u]+=1 queue=deque() fo...
find-eventual-safe-states
python solution using topological sort
shashank_2000
0
12
find eventual safe states
802
0.553
Medium
13,042
https://leetcode.com/problems/find-eventual-safe-states/discuss/2417353/Simple-oror-Easy-to-understand-or-Python
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: cache = {} graph = {idx : graph[idx] for idx in range(len(graph))} def dfs(currentIdx, visited): if len(graph[currentIdx]) == 0: return True ...
find-eventual-safe-states
Simple || Easy to understand | Python
tvishnu
0
48
find eventual safe states
802
0.553
Medium
13,043
https://leetcode.com/problems/find-eventual-safe-states/discuss/1873116/fast-DFS-with-memo-cache-or-96%2B
class Solution: def eventualSafeNodes(self, graph): return self.dfs(graph) def dfs(self, graph): ''' cache safe statue in dfs ''' safe_status = [None] * len(graph) def check_safe(node) -> bool: if safe_status[node] is None: safe_status[node] = False ...
find-eventual-safe-states
fast DFS with memo cache | 96+%
steve-jokes
0
64
find eventual safe states
802
0.553
Medium
13,044
https://leetcode.com/problems/find-eventual-safe-states/discuss/1823000/Python-DFS-74
class Solution: def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]: def dfs(node, result, visited): if node in visited: return visited[node] == [] visited[node] for n in graph[node]: visited[node].append(n) if...
find-eventual-safe-states
Python DFS 74%
Rush_P
0
95
find eventual safe states
802
0.553
Medium
13,045
https://leetcode.com/problems/find-eventual-safe-states/discuss/1736940/Python-Easy-to-understand-or-cycle-detection
class Solution: def dfs(self, graph, node, visited): if visited[node] == 2: return True visited[node] = 2 for nei in graph[node]: if visited[nei] != 1: if self.dfs(graph, nei, visited) == True: return True visited[node] = 1 ...
find-eventual-safe-states
[Python] Easy to understand | cycle detection
sanial2001
0
80
find eventual safe states
802
0.553
Medium
13,046
https://leetcode.com/problems/find-eventual-safe-states/discuss/1420421/Python3-Detect-cycle-using-DFS.-Simple-readable-solution-with-comments.
class Solution: def is_cycle(self, graph: List[List[int]], node: int, is_visited: Set, is_safe: Set) -> bool: # IF node is already visited, return cycle detected true if node in is_visited: return True # IF node is already explored, and no cycle detected, r...
find-eventual-safe-states
[Python3] Detect cycle using DFS. Simple readable solution with comments.
ssshukla26
0
78
find eventual safe states
802
0.553
Medium
13,047
https://leetcode.com/problems/unique-morse-code-words/discuss/2438206/Python-Elegant-and-Short-or-Two-lines-or-No-loops
class Solution: """ Time: O(n) Memory: O(n) """ MORSE = { 'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', 'q': '--.-', 'r': '.-.', 's': '...', 't':...
unique-morse-code-words
Python Elegant & Short | Two lines | No loops
Kyrylo-Ktl
5
395
unique morse code words
804
0.827
Easy
13,048
https://leetcode.com/problems/unique-morse-code-words/discuss/362150/Solution-in-Python-3-(beats-~100)-(two-lines)
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: M = ['.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..'] return len(set([''.join(map(lambda x: M[ord(x)-97], w)) for w...
unique-morse-code-words
Solution in Python 3 (beats ~100%) (two lines)
junaidmansuri
4
584
unique morse code words
804
0.827
Easy
13,049
https://leetcode.com/problems/unique-morse-code-words/discuss/2436772/Python-easy-understanding-solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: s = set() mos = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] for w in words: ...
unique-morse-code-words
Python easy-understanding solution
byroncharly3
2
246
unique morse code words
804
0.827
Easy
13,050
https://leetcode.com/problems/unique-morse-code-words/discuss/2166577/Python3-O(n*m)-oror-O(n)
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # O(n*m) || O(n) hashMap = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', ...
unique-morse-code-words
Python3 O(n*m) || O(n)
arshergon
2
64
unique morse code words
804
0.827
Easy
13,051
https://leetcode.com/problems/unique-morse-code-words/discuss/2621809/Python3-oror-Best-Solution-O(N*K)-where-k-is-a-max-length-of-string
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: arr = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] s =set() for word in words: strin...
unique-morse-code-words
Python3 || Best Solution O(N*K) , where k is a max length of string
shacid
1
31
unique morse code words
804
0.827
Easy
13,052
https://leetcode.com/problems/unique-morse-code-words/discuss/2441478/Simple-python-solution-85-speed
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: conversion = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] alphabet = 'abcdefghijklmnopqrstuvwxyz' ...
unique-morse-code-words
Simple python solution 85% speed
yusefgharib
1
23
unique morse code words
804
0.827
Easy
13,053
https://leetcode.com/problems/unique-morse-code-words/discuss/1862059/Python-(Simple-Approach-and-Beginner-Friendly)
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: arr = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] output = set() alpha = "abcdefghijklmnopqrstu...
unique-morse-code-words
Python (Simple Approach and Beginner-Friendly)
vishvavariya
1
101
unique morse code words
804
0.827
Easy
13,054
https://leetcode.com/problems/unique-morse-code-words/discuss/1316260/Python3-oror-Memory-less-than-99.5oror-Faster-than-84
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] #update dictionary with key temp(th...
unique-morse-code-words
Python3 || Memory less than 99.5%|| Faster than 84%
ana_2kacer
1
147
unique morse code words
804
0.827
Easy
13,055
https://leetcode.com/problems/unique-morse-code-words/discuss/1276632/Easy-Python-Solution(96.07)
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: d=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] x=[] c=0 for j in words: w=j ...
unique-morse-code-words
Easy Python Solution(96.07%)
Sneh17029
1
273
unique morse code words
804
0.827
Easy
13,056
https://leetcode.com/problems/unique-morse-code-words/discuss/1216673/Python-dictionary-solution-93-faster
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: dict = {} morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] diff = ord('a') for i in ...
unique-morse-code-words
Python dictionary solution 93% faster
bagdaulet881
1
146
unique morse code words
804
0.827
Easy
13,057
https://leetcode.com/problems/unique-morse-code-words/discuss/780193/Python3%3A-One-liner-(minus-the-line-to-define-the-alphabet)
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: ALPHABET = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] return len({"".join([ALPHABET[ord(c...
unique-morse-code-words
Python3: One-liner (minus the line to define the alphabet)
merdenberger31
1
54
unique morse code words
804
0.827
Easy
13,058
https://leetcode.com/problems/unique-morse-code-words/discuss/2841567/Python3-solution-Runtime-37-ms-Beats-92.72-Memory-13.8-MB-Beats-74.47
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: val = {'a' : ".-",'b' : "-...",'c' : "-.-.",'d' : "-..",'e' : ".",'f' : "..-.",'g' : "--.",'h' : "....",'i' : "..", 'j' : ".---",'k' : "-.-",'l' : ".-..",'m' : "--",'n' : "-.",'o' : "---",'p' : ".--.", 'q' : "--.-",'r': ".-.",'s'...
unique-morse-code-words
Python3 solution Runtime 37 ms Beats 92.72% Memory 13.8 MB Beats 74.47%
SupriyaArali
0
1
unique morse code words
804
0.827
Easy
13,059
https://leetcode.com/problems/unique-morse-code-words/discuss/2827841/PYTHON3-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: dic = [".-","-...","-.-.","-..",".","..-.","--.","....",".." \ ,".---","-.-",".-..","--","-.","---",".--.","--.-" \ ,".-.","...","-","..-","...-",".--","-..-","-.--","--.."] A = dict( zip( string...
unique-morse-code-words
PYTHON3 Solution
Gurugubelli_Anil
0
4
unique morse code words
804
0.827
Easy
13,060
https://leetcode.com/problems/unique-morse-code-words/discuss/2816341/Fast-and-Simple-Solution-Python
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: values = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] checked = set() for i in range(0, len(word...
unique-morse-code-words
Fast and Simple Solution - Python
PranavBhatt
0
3
unique morse code words
804
0.827
Easy
13,061
https://leetcode.com/problems/unique-morse-code-words/discuss/2799108/(-)-Easy-Commented-Simple-Solution
class Solution(object): def uniqueMorseRepresentations(self, words): setOfAlltransformations=set() #a unique set which will contain unique eles morze = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-",...
unique-morse-code-words
( ͡° ͜ʖ ͡°) Easy Commented Simple Solution
fa19-bcs-016
0
2
unique morse code words
804
0.827
Easy
13,062
https://leetcode.com/problems/unique-morse-code-words/discuss/2797499/Python-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: l=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] s=set() st="" for word in words: ...
unique-morse-code-words
Python Solution
sbhupender68
0
2
unique morse code words
804
0.827
Easy
13,063
https://leetcode.com/problems/unique-morse-code-words/discuss/2781388/Python3-Easier-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: s = set() mos = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] for w in words: ...
unique-morse-code-words
Python3 Easier Solution
avs-abhishek123
0
1
unique morse code words
804
0.827
Easy
13,064
https://leetcode.com/problems/unique-morse-code-words/discuss/2751647/Simple-Python-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse_code_array = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] result = set() for word in words: ...
unique-morse-code-words
Simple Python Solution
dnvavinash
0
4
unique morse code words
804
0.827
Easy
13,065
https://leetcode.com/problems/unique-morse-code-words/discuss/2743419/Python-easy-to-understand
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morsecodes = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] alphabet = ["a", "b", "c", "d", "e", "f", "g",...
unique-morse-code-words
Python, easy to understand
vegancyberpunk
0
5
unique morse code words
804
0.827
Easy
13,066
https://leetcode.com/problems/unique-morse-code-words/discuss/2736849/Python-simple-solution-using-a-dictionary-and-a-set
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: def transform(word): morse_alphabet = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] engli...
unique-morse-code-words
Python simple solution using a dictionary and a set
Mark_computer
0
6
unique morse code words
804
0.827
Easy
13,067
https://leetcode.com/problems/unique-morse-code-words/discuss/2718770/Python3-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] decoder = {chr(i):morse[i-97] for i in range(97,123...
unique-morse-code-words
Python3 Solution
sipi09
0
2
unique morse code words
804
0.827
Easy
13,068
https://leetcode.com/problems/unique-morse-code-words/discuss/2605446/43-ms-faster-than-81.45-of-Python3
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: arr = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] l = [] for i in words: s = "" for j in i: ...
unique-morse-code-words
43 ms, faster than 81.45% of Python3
Abdulahad_Abduqahhorov
0
31
unique morse code words
804
0.827
Easy
13,069
https://leetcode.com/problems/unique-morse-code-words/discuss/2449235/Python-3-Explanied-solution-with-Dict
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # In this solution, we want to count unique morse translations of the input words # Let's use a dict (seen) for our output, because it makes it easy to only record new unique records seen = {} ...
unique-morse-code-words
[Python 3] Explanied solution with Dict
connorthecrowe
0
13
unique morse code words
804
0.827
Easy
13,070
https://leetcode.com/problems/unique-morse-code-words/discuss/2442152/98.45-memory-efficient-solution-using-set-and-ord-in-Python
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-", ".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-", ".--","-..-","-.--","--.."] res = set() ...
unique-morse-code-words
98.45% memory efficient solution using set and ord in Python
ankurbhambri
0
15
unique morse code words
804
0.827
Easy
13,071
https://leetcode.com/problems/unique-morse-code-words/discuss/2441222/Simple-Hashmap-Solution-or-Python
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: trans = {'a':".-", 'b':"-...", 'c':"-.-.", 'd':"-..", 'e':".", 'f':"..-.", 'g':"--.", 'h':"....", 'i':"..", 'j':".---", 'k':"-.-", 'l':".-..", 'm':"--", 'n':"-.", 'o':"---", 'p':".--.", 'q':"--.-", 'r':".-.", 's':"...", 't':"-", ...
unique-morse-code-words
Simple Hashmap Solution | Python
Abhi_-_-
0
8
unique morse code words
804
0.827
Easy
13,072
https://leetcode.com/problems/unique-morse-code-words/discuss/2441149/Python-oror-Simple-and-Short-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse_code = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] res = set() for word in words: ...
unique-morse-code-words
Python || Simple and Short Solution
Gyalecta
0
13
unique morse code words
804
0.827
Easy
13,073
https://leetcode.com/problems/unique-morse-code-words/discuss/2441062/Python-Short-and-Easy-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # Morse Code Words Charachter Representation stored in Dictionary morse = { "a":".-", "b":"-...", "c":"-.-.", "d":"-..", "e":".", "f":"..-.", ...
unique-morse-code-words
Python Short & Easy Solution
arshdeepsahni
0
4
unique morse code words
804
0.827
Easy
13,074
https://leetcode.com/problems/unique-morse-code-words/discuss/2440957/Python3-oror-Optimal-and-Straight-Forward
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] res = set() for word in words: ...
unique-morse-code-words
Python3 || Optimal & Straight Forward
Dewang_Patil
0
5
unique morse code words
804
0.827
Easy
13,075
https://leetcode.com/problems/unique-morse-code-words/discuss/2440215/Python-Easy-and-Simple-using-Set-Top-98-Space
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # 25 len, 0 = a, ... 26 = z morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] # Not counting ...
unique-morse-code-words
Python Easy and Simple using Set, Top 98% Space
drblessing
0
11
unique morse code words
804
0.827
Easy
13,076
https://leetcode.com/problems/unique-morse-code-words/discuss/2439765/Simple-Python-Solution-or-Easy-and-Fast
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: t = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] s = set() for word in words: code =...
unique-morse-code-words
Simple Python Solution | Easy and Fast
prameshbajra
0
12
unique morse code words
804
0.827
Easy
13,077
https://leetcode.com/problems/unique-morse-code-words/discuss/2439663/Simple-Python-solution-Set
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: #First, create a dict with the morse equivalencies morse_dict = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', '...
unique-morse-code-words
Simple Python solution - Set
GMFB
0
5
unique morse code words
804
0.827
Easy
13,078
https://leetcode.com/problems/unique-morse-code-words/discuss/2439582/GolangPython-O(N)-time-or-O(N)-space
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: letter_to_code = {"a":".-", "b":"-...", "c":"-.-.", "d":"-..", "e":".", "f":"..-.", ...
unique-morse-code-words
Golang/Python O(N) time | O(N) space
vtalantsev
0
7
unique morse code words
804
0.827
Easy
13,079
https://leetcode.com/problems/unique-morse-code-words/discuss/2439412/Python-Super-Simple-Cake-Walk-Solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # Dictionary containing all the corresponding Morse code values of characters dict = {'a':'.-', 'b':'-...', 'c':'-.-.', 'd':'-..', 'e':'.', 'f':'..-.', 'g':'--.', ...
unique-morse-code-words
🐍🐲 Python Super Simple Cake Walk Solution 🐲🐍
sHadowSparK
0
11
unique morse code words
804
0.827
Easy
13,080
https://leetcode.com/problems/unique-morse-code-words/discuss/2439262/Python3-String-manipulationorSimple-and-understandable-approachorEasy
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: alpha=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] st=[] for i in words: s="" ...
unique-morse-code-words
Python3 String manipulation|Simple and understandable approach|Easy
sushant332
0
5
unique morse code words
804
0.827
Easy
13,081
https://leetcode.com/problems/unique-morse-code-words/discuss/2439249/Python-Solution-with-explanation-in-comments
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # Create an empty set s = set() # Initialize the morse code with code for each letter in a list named as code. code = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---"...
unique-morse-code-words
Python Solution with explanation in comments
yashkumarjha
0
2
unique morse code words
804
0.827
Easy
13,082
https://leetcode.com/problems/unique-morse-code-words/discuss/2439003/Python3-oror-Easy-Solution-with-Explanation-oror-Faster
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: li = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] a = ord('a') s1 = set() for word in wo...
unique-morse-code-words
Python3 || Easy Solution with Explanation || Faster
NITIN_DS
0
4
unique morse code words
804
0.827
Easy
13,083
https://leetcode.com/problems/unique-morse-code-words/discuss/2438706/Python3-HashTable-and-Set-based-solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: # Morse code mapping to alphabets. mapping = { "a": ".-", "b": "-...", "c": "-.-.", "d": "-..", "e": ".", "f": "..-.", "g": "--.", ...
unique-morse-code-words
[Python3] HashTable and Set based solution
aakash111295
0
4
unique morse code words
804
0.827
Easy
13,084
https://leetcode.com/problems/unique-morse-code-words/discuss/2438705/Simple-and-Clean-Python3-code-using-2-'FOR-LOOPS'-oror-Beginner-friendly
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: c=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] s="abcdefghijklmnopqrstuvwxyz" codes=[] for i in words: morse='' ...
unique-morse-code-words
Simple and Clean Python3 code using 2 'FOR LOOPS' || Beginner friendly
keertika27
0
6
unique morse code words
804
0.827
Easy
13,085
https://leetcode.com/problems/unique-morse-code-words/discuss/2438397/python3-simple-solution
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: ans = set() morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] for word in words: ...
unique-morse-code-words
python3, simple solution
pjy953
0
2
unique morse code words
804
0.827
Easy
13,086
https://leetcode.com/problems/unique-morse-code-words/discuss/2438041/Python3-One-Liner-With-Breakdown
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: dictionary = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] def transform(word: str) -> str: r...
unique-morse-code-words
[Python3] One Liner With Breakdown
jeffreyhu8
0
5
unique morse code words
804
0.827
Easy
13,087
https://leetcode.com/problems/unique-morse-code-words/discuss/2438041/Python3-One-Liner-With-Breakdown
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: return len(set(''.join([".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."][ord(ch) - ord('a')] for ch in word) for word...
unique-morse-code-words
[Python3] One Liner With Breakdown
jeffreyhu8
0
5
unique morse code words
804
0.827
Easy
13,088
https://leetcode.com/problems/unique-morse-code-words/discuss/2438041/Python3-One-Liner-With-Breakdown
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: return len(set( # find the length of the set of all morse transformations (i.e. find the number of different transformations) ''.join( # join together the morse translation of each individual char to get the morse of ...
unique-morse-code-words
[Python3] One Liner With Breakdown
jeffreyhu8
0
5
unique morse code words
804
0.827
Easy
13,089
https://leetcode.com/problems/unique-morse-code-words/discuss/2437898/As-easy-as-it-can-get-python3-solution-with-complexity-analysis
class Solution: # O(len(words) * m) time, m --> the longest word in words # O(len(words)) space, # Apporach: array, hashset def uniqueMorseRepresentations(self, words: List[str]) -> int: morse_code = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--....
unique-morse-code-words
As easy as it can get python3 solution with complexity analysis
destifo
0
3
unique morse code words
804
0.827
Easy
13,090
https://leetcode.com/problems/unique-morse-code-words/discuss/2437713/Hashing-oror-Easy-understanding-oror-98-Efficient
class Solution(object): def uniqueMorseRepresentations(self, words): """ :type words: List[str] :rtype: int """ listWord = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--"...
unique-morse-code-words
Hashing || Easy-understanding || 98% Efficient
mridulbhas
0
18
unique morse code words
804
0.827
Easy
13,091
https://leetcode.com/problems/unique-morse-code-words/discuss/2437634/Python3-Solution-with-using-hashset
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: alphabet = [".-","-...","-.-.","-..",".","..-.","--.", "....","..",".---","-.-",".-..","--","-.", "---",".--.","--.-",".-.","...","-","..-", "...-",".--","-..-","-.--","--.."] ...
unique-morse-code-words
[Python3] Solution with using hashset
maosipov11
0
4
unique morse code words
804
0.827
Easy
13,092
https://leetcode.com/problems/unique-morse-code-words/discuss/2437493/Python-easy-solution-(32-ms-beats-98)
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] d = {chr(i+96):morse[i-1] for i in range(1, 27)} ...
unique-morse-code-words
Python easy solution (32 ms, beats 98%)
CasualTrash
0
9
unique morse code words
804
0.827
Easy
13,093
https://leetcode.com/problems/unique-morse-code-words/discuss/2437261/Python-soln-using-set
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: charToMorse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] wordSet = set() for...
unique-morse-code-words
Python soln using set
logeshsrinivasans
0
3
unique morse code words
804
0.827
Easy
13,094
https://leetcode.com/problems/unique-morse-code-words/discuss/2437230/python-runtime-29-ms
class Solution(object): def uniqueMorseRepresentations(self, words): """ :type words: List[str] :rtype: int """ morse_chars = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..", "--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-....
unique-morse-code-words
python - runtime 29 ms
user2354hl
0
4
unique morse code words
804
0.827
Easy
13,095
https://leetcode.com/problems/unique-morse-code-words/discuss/2437161/48ms-or-fast-and-easy
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: code=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] transformation=set() for word in words: ...
unique-morse-code-words
48ms | fast & easy
ayushigupta2409
0
7
unique morse code words
804
0.827
Easy
13,096
https://leetcode.com/problems/split-array-with-same-average/discuss/120654/Simple-python-with-explanation
class Solution(object): def splitArraySameAverage(self, A): if len(A)==1: return False global_avg = sum(A)/float(len(A)) for lenB in range(1, len(A)/2+1): if int(lenB*global_avg) == lenB*global_avg: if self.exist(lenB*global_avg, lenB, A): retu...
split-array-with-same-average
Simple python with explanation
licaiuu
26
4,200
split array with same average
805
0.259
Hard
13,097
https://leetcode.com/problems/split-array-with-same-average/discuss/663594/Python-Lee215's-solution-with-explanations-and-added-memorization-pass-new-case
class Solution: def splitArraySameAverage(self, A: List[int]) -> bool: # A subfunction that see if total k elements sums to target # target is the goal, k is the number of elements in set B, i is the index we have traversed through so far mem = {} def find(target, k, i): # if we are down searching for k e...
split-array-with-same-average
[Python] Lee215's solution with explanations and added memorization [pass new case]
lichuan199010
9
1,300
split array with same average
805
0.259
Hard
13,098
https://leetcode.com/problems/split-array-with-same-average/discuss/471354/Python-3-DP-solution
class Solution: def splitArraySameAverage(self, A: List[int]) -> bool: A.sort() DP=[set() for _ in range(len(A)//2+1)] #DP[i] stores the all available sum with i items in a bracket all_sum=sum(A) DP[0]=set([0]) for item in A: #iterate over items in the lis...
split-array-with-same-average
Python 3 DP solution
wangzi100
8
892
split array with same average
805
0.259
Hard
13,099