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/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/discuss/2401947/Python-easy-to-read-and-understand-or-prefix-sum | class Solution:
def maxSideLength(self, mat: List[List[int]], threshold: int) -> int:
m, n = len(mat), len(mat[0])
t = [[0 for _ in range(n+1)] for _ in range(m+1)]
for i in range(1, m+1):
for j in range(1, n+1):
t[i][j] = t[i][j-1] + t[i-1][j] - t[i-1][j... | maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold | Python easy to read and understand | prefix-sum | sanial2001 | 0 | 100 | maximum side length of a square with sum less than or equal to threshold | 1,292 | 0.532 | Medium | 19,200 |
https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/discuss/1708213/Python-or-Prefix-Sum-%2B-Binary-Search-or-Template | class Solution:
def maxSideLength(self, mat: List[List[int]], threshold: int) -> int:
m, n = len(mat), len(mat[0])
prefix = copy.deepcopy(mat)
rsum = 0
for i in range(m):
rsum += mat[i][0]
prefix[i][0] = rsum
csum = 0
for ... | maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold | Python | Prefix Sum + Binary Search | Template | detective_dp | 0 | 169 | maximum side length of a square with sum less than or equal to threshold | 1,292 | 0.532 | Medium | 19,201 |
https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/discuss/1652656/python-simple-solution-or-83.92 | class Solution:
def maxSideLength(self, mat: List[List[int]], threshold: int) -> int:
m,n = len(mat),len(mat[0])
# 2-dimention prefix sum array
P = [[0]*(n+1) for _ in range(m+1)]
for i in range(1, m+1):
for j in range(1, n+1):
P[i][j] = P[i-1][j]... | maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold | python simple solution | 83.92% | 1579901970cg | 0 | 158 | maximum side length of a square with sum less than or equal to threshold | 1,292 | 0.532 | Medium | 19,202 |
https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/discuss/451902/Python-3-(beats-100)-(ten-lines) | class Solution:
def maxSideLength(self, G: List[List[int]], t: int) -> int:
M, N, m = len(G), len(G[0]), 0; S = [[0]*(N+1) for _ in range(M+1)]
S[1] = list(itertools.accumulate([0]+G[0]))
for i in range(1,M):
s = list(itertools.accumulate(G[i]))
for j in range(N): S[i... | maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold | Python 3 (beats 100%) (ten lines) | junaidmansuri | 0 | 344 | maximum side length of a square with sum less than or equal to threshold | 1,292 | 0.532 | Medium | 19,203 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758292/Python-Simple-and-Easy-Way-to-Solve-or-95-Faster | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
# x, y, obstacles, steps
q = deque([(0,0,k,0)])
seen = set()
while q:
x, y, left, steps = q.popleft()
if (x,y,left) in seen o... | shortest-path-in-a-grid-with-obstacles-elimination | ✔️ Python Simple and Easy Way to Solve | 95% Faster 🔥 | pniraj657 | 14 | 995 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,204 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2759679/Python-or-95-faster-or-Easy-and-clean-code-using-BFS-approach | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
if len(grid) == 1 and len(grid[0]) == 1:
return 0
q = deque([(0,0,k,0)])
visited = set([(0,0,k)])
if (len(grid)-1) + (len(grid[0])-1) < k:
return (len(grid)-1) + (len(grid[0... | shortest-path-in-a-grid-with-obstacles-elimination | Python | 95% faster | Easy and clean code using BFS approach | __Asrar | 5 | 289 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,205 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1485029/easy-understand-python-bfs-solution | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m = len(grid)
n = len(grid[0])
if m == 1 and n == 1:
return 0
ans = 1
visited = [[-1] * n for _ in range(m)]
visited[0][0] = k
queue = [(0, 0, k)]
while queue:
... | shortest-path-in-a-grid-with-obstacles-elimination | easy understand python bfs solution | alex391a | 5 | 130 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,206 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1854463/Python-3-Easy-and-clear-solution. | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
queue=deque()
queue.append([0,0,k,0])
visited=set()
steps=-1
while queue:
i,j,r,steps=queue.popleft()
if (i,j,r) not in visited:
if i-1>=0 and grid[i-1][j]!=1:
queue.append([i-1,j,r,steps+1])
if i-1>=0 and grid[i... | shortest-path-in-a-grid-with-obstacles-elimination | [Python 3] Easy and clear solution. | RaghavGupta22 | 4 | 647 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,207 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1771716/Python-Simple-BFS | class Solution:
def shortestPath(self, grid: list[list[int]], k: int) -> int:
R, C = len(grid), len(grid[0])
queue = [(0, 0, 0, 0)]
visited = {(0, 0, 0)}
for r, c, obstacleCnt, stepCnt in queue:
if r + 1 == R and c + 1 == C:
return stepCnt
for... | shortest-path-in-a-grid-with-obstacles-elimination | [Python] Simple BFS | eroneko | 3 | 214 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,208 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2760734/Python-Cleanest-Crisp-Solution-or-Brain-Friedly-or-Understand-in-One-Read-or-With-IMP-comments | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
directions = [[-1,0],[0,1],[1,0],[0,-1]]
# in vis list, we will store "number of obstacles we can still remove" further
visited = [[-1]*n for _ in range(m)]
... | shortest-path-in-a-grid-with-obstacles-elimination | Python Cleanest Crisp Solution | Brain Friedly | Understand in One Read | With IMP comments | dhanrajbhosale7797 | 2 | 53 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,209 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758876/python3-code-explained | class Solution:
def shortestPath(self, grid: list[list[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
# [1] this check significantly improves runtime, i.e.,
# we can use path (0,0) -> (0,n-1) -> (m-1,n-1)
if k >= m + n - 2: return m + n - 2
# [2] we... | shortest-path-in-a-grid-with-obstacles-elimination | python3 code explained | rupamkarmakarcr7 | 1 | 75 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,210 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2834632/Function-based-A*-search-style | class Solution:
# manhattan distance function
def mh_distance(self, row, col) :
return (self.target_row - row) + (self.target_col - col)
# get next state singular
def get_next_state(self, new_row, new_col, current_state) :
new_eliminations = current_state[2] - self.grid[new_row][new... | shortest-path-in-a-grid-with-obstacles-elimination | Function based A* search style | laichbr | 0 | 1 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,211 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2761165/Easy-to-Understand-BFS-Solution | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
rows, columns = len(grid), len(grid[0])
seen = set()
steps = 0
q = deque([(0, 0, k)])
while q:
length = len(q)
for i in range(length):
x, y, r = q.popleft()
... | shortest-path-in-a-grid-with-obstacles-elimination | Easy to Understand, BFS Solution | user6770yv | 0 | 18 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,212 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2761159/Python!-As-short-as-it-gets! | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
n , m = len(grid), len(grid[0])
k = min(k, n + m + 1)
adj, dp, mark = defaultdict(list), defaultdict(lambda: n * m + 1), defaultdict(bool)
for z in range(k+1):
for x in range(n):
... | shortest-path-in-a-grid-with-obstacles-elimination | 😎Python! As short as it gets! | aminjun | 0 | 13 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,213 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2760996/Python-solution-using-BFS-and-Memoisation.-Breadth-First-Search | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
flag = [[[0]*n for i in range(m)]for j in range(k+1)]
steps = 0
q = [[0,0,k]]
di = [[0,1], [1,0], [-1,0], [0,-1]]
while q:
size = len(q)
... | shortest-path-in-a-grid-with-obstacles-elimination | Python solution using BFS and Memoisation. [Breadth First Search] | abhishekgoel1999 | 0 | 9 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,214 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2760671/Python3-Solution-with-using-bfs | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
if len(grid) == 1 and len(grid[0]) == 1:
return 0
if k > (len(grid) - 1 + len(grid[0]) - 1):
return len(grid) + len(grid[0]) - 2
"""
begin_state:
begin_x... | shortest-path-in-a-grid-with-obstacles-elimination | [Python3] Solution with using bfs | maosipov11 | 0 | 6 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,215 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2760467/Python-or-BFS-solution | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
rows, cols = len(grid), len(grid[0])
q = deque()
# r, c, pathLength, remaining_k
q.append((0, 0, 0, k))
seen = set()
while q:
r, c, pathLength, kRemain = q.popleft()
... | shortest-path-in-a-grid-with-obstacles-elimination | Python | BFS solution | KevinJM17 | 0 | 9 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,216 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2760023/Help-BFS-TLE-what's-wrong-and-where-to-improve | class Solution:
def shortestPath(self, grid: List[List[int]], K: int) -> int:
def inbound(r, c):
if r<0 or c<0 or r>=len(grid) or c>=len(grid[0]): return False
return True
q = collections.deque([(0, 0, K)])
seen = set()
path = 0
while len(q)>0:
... | shortest-path-in-a-grid-with-obstacles-elimination | [Help] BFS TLE, what's wrong and where to improve ? | dyxuki | 0 | 8 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,217 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2759836/Python-BFS-Check-if-the-visited-cell-has-moreless-remaining_k-count | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
m, n = len(grid), len(grid[0])
def inbound(x, y):
return 0 <= x < m and 0 <= y < n
# row, col, remaining_k, steps
q = collections.deque( [(0, 0, ... | shortest-path-in-a-grid-with-obstacles-elimination | [Python] BFS - Check if the visited cell has more/less `remaining_k` count | Paranoidx | 0 | 16 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,218 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2759377/Python-solution-with-explaination | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
# [1] this check significantly improves runtime, i.e.,
# we can use path (0,0) -> (0,n-1) -> (m-1,n-1)
if k >= m + n - 2: return m + n - 2
# [2] we use dequ... | shortest-path-in-a-grid-with-obstacles-elimination | Python solution with explaination | avs-abhishek123 | 0 | 14 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,219 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758829/python3-bfs | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
if m == 1 and n ==1: return 0
queue = [(0,0,0)]
step = 1
visited = {(0,0):0}
while queue:
length = len(queue)
new_queue = []
... | shortest-path-in-a-grid-with-obstacles-elimination | python3, bfs | pjy953 | 0 | 10 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,220 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758812/Python-BFS | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
if m == 1 and n == 1:
return 0
pos = [(1, 0), (-1, 0), (0, 1), (0, -1)]
maxK = [[-1 for _ in range(n)] for _ in range(m)]
queue = [(0, 0, k, 0)]
... | shortest-path-in-a-grid-with-obstacles-elimination | [Python] BFS | mingyang-tu | 0 | 12 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,221 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758697/Python3-or-Dijkstra | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
heap = [(0, 0, 0, 0)]
seen = set()
n, m = len(grid), len(grid[0])
def checkInBound(x, y):
return 0 <= x < n and 0 <= y < m
while heap:
d, kt, i, j = heapq.heappop(heap)
... | shortest-path-in-a-grid-with-obstacles-elimination | Python3 | Dijkstra | vikinam97 | 0 | 17 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,222 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758649/BFS-Python-Solution | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m = len(grid)
n = len(grid[0])
queue = deque()
seen = set()
queue.append(((0, 0), 0))
seen.add((0, 0, 0))
moves = [(0, 1), (0, -1), (-1, 0), (1, 0)]
steps =... | shortest-path-in-a-grid-with-obstacles-elimination | BFS Python Solution | mansoorafzal | 0 | 12 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,223 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2758351/Python3-BFS-but-using-heap | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
mx, nx = len(grid), len(grid[0])
h = [(0, 0, 0, 0)]
visited = set()
while h:
s, n, i, j = heappop(h)
if i<0 or i>=mx or j<0 or j>=nx or (i, j, n) in visited:
... | shortest-path-in-a-grid-with-obstacles-elimination | Python3 BFS, but using heap | godshiva | 0 | 15 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,224 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2603134/Python-BFS-Simple-ans-Easy | class Solution:
# Simple BFS Solution in Python
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
state = (0, 0, k)
queue = deque([(0, state)])
seen = set([state])
while que... | shortest-path-in-a-grid-with-obstacles-elimination | Python BFS Simple ans Easy | shiv-codes | 0 | 111 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,225 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2536537/Python-or-BFS | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
def bfs(grid, k):
q = collections.deque()
q.append((0, 0, k, 0))
visited = set()
ROWS = len(grid)
COLS = len(grid[0])
if ROWS == 1 and COLS == 1:
return 0
visited.add((0, 0, k))
while q:
r, c, k, pathLen... | shortest-path-in-a-grid-with-obstacles-elimination | Python | BFS | Mark5013 | 0 | 173 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,226 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/2340692/Python-BFS-solution | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
moves = [[-1, 0], [1, 0], [0, -1], [0, 1]]
M, N = len(grid), len(grid[0])
if M == 1 and N == 1:
return 0
q = deque()
q.append((0, 0, 0))
visited = set()
visited.add((0, 0... | shortest-path-in-a-grid-with-obstacles-elimination | Python BFS solution | pivovar3al | 0 | 115 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,227 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1922331/Python-easy-to-read-and-understand-or-BFS | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
visit = set()
visit.add((0, 0, 0))
q = [[0, 0, 0, 0]]
while q:
x, y, obstacle, path = q.pop(0)
if x == m-1 and y == n-1:
... | shortest-path-in-a-grid-with-obstacles-elimination | Python easy to read and understand | BFS | sanial2001 | 0 | 100 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,228 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1911319/Python-BFS-and-A*-Search-with-explanation-or-Beats-95 | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
# find neighbours of node
def neighbour(node):
i,j = node
moves = ((1,0),(0,1),(-1,0),(0,-1)) # up, down, left, or right
return [ (i+di... | shortest-path-in-a-grid-with-obstacles-elimination | [Python] BFS and A* Search with explanation | Beats 95% | haydarevren | 0 | 110 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,229 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1911319/Python-BFS-and-A*-Search-with-explanation-or-Beats-95 | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
# find neighbours of node
def neighbour(node):
i,j = node
moves = ((1,0),(0,1),(-1,0),(0,-1)) # up, down, left, or right
return [ (i+di... | shortest-path-in-a-grid-with-obstacles-elimination | [Python] BFS and A* Search with explanation | Beats 95% | haydarevren | 0 | 110 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,230 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1719750/Python-BFS-easy-to-follow-solution | class Solution:
def findAdjacentPositions(self, i, j, distance, k, grid, seen):
adjacentPositions = []
if i > 0 :
adjacentPositions.append((i-1, j, k, distance + 1))
if i < len(grid)-1:
adjacentPositions.append((i+1, j, k, distance + 1))
if j > 0:
... | shortest-path-in-a-grid-with-obstacles-elimination | Python BFS easy to follow solution | user7857pf | 0 | 237 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,231 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1424448/Python%3A-BFS | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
M,N=len(grid),len(grid[0])
steps=0
q,seen=[(0,0,0)],set()
while q:
for _ in range(len(q)):
r,c,used=q.pop(0)
if (r,c)==(M-1,N-1):
return step... | shortest-path-in-a-grid-with-obstacles-elimination | Python: BFS | SeraphNiu | 0 | 115 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,232 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/453721/Python3-breadth-first-search | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0]) #dimension
if k >= m+n-2: return m+n-2 #key for speed 668ms -> 52ms
level = 0
queue = [(0, 0, 0)]
visited = set(queue)
#bfs at most ... | shortest-path-in-a-grid-with-obstacles-elimination | [Python3] breadth-first search | ye15 | 0 | 100 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,233 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1485320/Python3-BFS-%2B-Note-on-DFS | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
visited, m, n = set(), len(grid), len(grid[0])
@cache
def dfs(i, j, k):
key = (i, j)
if (k < 0 or i >= m or i < 0 or j >= n or j < 0 or key in visited):
return math.inf
... | shortest-path-in-a-grid-with-obstacles-elimination | Python3 - BFS + Note on DFS ✅ | Bruception | -1 | 310 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,234 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/1485320/Python3-BFS-%2B-Note-on-DFS | class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n, steps = len(grid), len(grid[0]), 0
seen, queue, dirs = set([(0, 0, k)]), deque([(0, 0, k)]), [(1, 0), (-1, 0), (0, 1), (0, -1)]
while (queue):
for _ in range(len(queue)):
i, j, k =... | shortest-path-in-a-grid-with-obstacles-elimination | Python3 - BFS + Note on DFS ✅ | Bruception | -1 | 310 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,235 |
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/discuss/452144/Python-3-(beats-100)-(40-ms)-(eleven-lines)-(BFS) | class Solution:
def shortestPath(self, G: List[List[int]], k: int) -> int:
M, N, P, Q, D, L = len(G)-1, len(G[0])-1, [(0,0,0)], [], {}, 0
if k >= M+N: return M+N
while P:
for (x,y,s) in P:
if (x,y) == (M,N): return L
for i,j in (x-1,y),(x,y+1),(x+1... | shortest-path-in-a-grid-with-obstacles-elimination | Python 3 (beats 100%) (40 ms) (eleven lines) (BFS) | junaidmansuri | -4 | 503 | shortest path in a grid with obstacles elimination | 1,293 | 0.456 | Hard | 19,236 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/468107/Python-3-lightning-fast-one-line-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len([x for x in nums if len(str(x)) % 2 == 0]) | find-numbers-with-even-number-of-digits | Python 3 lightning fast one line solution | denisrasulev | 31 | 7,300 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,237 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/616315/Several-python-sol-sharing-w-Reference | class Solution:
def findNumbers(self, nums: List[int]) -> int:
counter = 0
for number in nums:
if len( str(number) ) % 2 == 0:
counter += 1
return counter | find-numbers-with-even-number-of-digits | Several python sol sharing [w/ Reference] | brianchiang_tw | 8 | 719 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,238 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/616315/Several-python-sol-sharing-w-Reference | class Solution:
def findNumbers(self, nums: List[int]) -> int:
# output by generator expression
return sum( (1 for number in nums if len(str(number))%2 == 0), 0 ) | find-numbers-with-even-number-of-digits | Several python sol sharing [w/ Reference] | brianchiang_tw | 8 | 719 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,239 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/616315/Several-python-sol-sharing-w-Reference | class Solution:
def findNumbers(self, nums: List[int]) -> int:
even_digit_width = lambda number: ( len( str(number) ) % 2 == 0 )
return sum( map(even_digit_width, nums) , 0 ) | find-numbers-with-even-number-of-digits | Several python sol sharing [w/ Reference] | brianchiang_tw | 8 | 719 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,240 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/457649/Python-3-(one-line)-(beats-100) | class Solution:
def findNumbers(self, N: List[int]) -> int:
return sum(len(str(n)) % 2 == 0 for n in N)
- Junaid Mansuri
- Chicago, IL | find-numbers-with-even-number-of-digits | Python 3 (one line) (beats 100%) | junaidmansuri | 3 | 790 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,241 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1067611/Python-simple-solution(Faster-than-91.41-and-very-EASY-to-understand) | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for i in nums:
i = str(i)
if len(i) % 2 == 0:
count += 1
return count
``` | find-numbers-with-even-number-of-digits | Python simple solution(Faster than 91.41% and very EASY to understand) | Sissi0409 | 2 | 271 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,242 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2773355/1-Liner-using-map | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum(not n&1 for n in map(len, map(str, nums))) | find-numbers-with-even-number-of-digits | 1 Liner using map | Mencibi | 1 | 50 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,243 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2514057/Simple-python-sol | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for num in nums:
if len(str(num)) % 2 == 0:
count += 1
return count | find-numbers-with-even-number-of-digits | Simple python sol | aruj900 | 1 | 50 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,244 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2086379/Python3-brute-force-to-optimal-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
# return self.solOne(nums)
# return self.solTwo(nums)
return self.solThree(nums)
# O(N) || O(1) 105ms 12.77%
# brute force
def solOne(self, numArray):
if not numArray:
return 0
counter = ... | find-numbers-with-even-number-of-digits | Python3 brute force to optimal solution | arshergon | 1 | 74 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,245 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1587238/Python3-or-Check-number-length-as-a-string | class Solution:
def findNumbers(self, nums: List[int]) -> int:
evenCount = 0
for num in nums:
if len(str(num)) % 2 == 0:
evenCount += 1
return evenCount | find-numbers-with-even-number-of-digits | Python3 | Check number length as a string | JM_Pranav | 1 | 77 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,246 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1450724/Python-One-Liner | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return [len(str(num)) % 2 for num in nums ].count(0) | find-numbers-with-even-number-of-digits | Python One Liner | vatsea | 1 | 111 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,247 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1105917/Python3-simple-one-liner-faster-than-95 | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return([len(str(i))%2 for i in nums].count(0)) | find-numbers-with-even-number-of-digits | Python3 simple one liner faster than 95% | suhasmr2911 | 1 | 188 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,248 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/942874/Easy-Python-Solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum(len(str(i))%2==0 for i in nums) | find-numbers-with-even-number-of-digits | Easy Python Solution | lokeshsenthilkumar | 1 | 261 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,249 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/781518/Python-1-liner | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum([len(str(i))%2==0 for i in nums]) | find-numbers-with-even-number-of-digits | Python 1-liner | lokeshsenthilkumar | 1 | 200 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,250 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/749193/Python-solution-WITHOUT-using-str()-and-len() | class Solution:
def findNumbers(self, nums: List[int]) -> int:
total_count = 0
for i in nums:
count = 0
while i > 0:
i = i // 10
count += 1
if count % 2 == 0:
total_count += 1
return total_count | find-numbers-with-even-number-of-digits | Python solution WITHOUT using str() and len() | CzechAssassin | 1 | 121 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,251 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/693880/PythonC-Find-Numbers-with-Even-Number-of-Digits | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for i in nums:
if len(str(i))%2 == 0:
count += 1
return count | find-numbers-with-even-number-of-digits | [Python/C] Find Numbers with Even Number of Digits | abhijeetmallick29 | 1 | 173 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,252 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/683309/Python-Very-Easy-One-Liner. | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len([x for x in nums if len(str(x)) % 2 == 0]) | find-numbers-with-even-number-of-digits | Python, Very Easy One-Liner. | Cavalier_Poet | 1 | 143 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,253 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/669185/Python3-easy-one-line-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return [len(str(num))%2==0 for num in nums].count(True) | find-numbers-with-even-number-of-digits | Python3 easy one line solution | aj_to_rescue | 1 | 81 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,254 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/589748/Python3-one-line-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len(list(filter(lambda x: len(str(x))%2==0, nums))) | find-numbers-with-even-number-of-digits | Python3 one line solution | 2736618 | 1 | 236 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,255 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/545439/easy-python-3-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
if len(nums)<1 and len(nums)>500:
return 0
count1=0 # to count number of even digits
for i in range(0,(len(nums))):
count = 0 # to count digits in a number
while nums[i]: # loop that counts dig... | find-numbers-with-even-number-of-digits | easy python 3 solution | syednabi932 | 1 | 95 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,256 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/533943/Python3%3A-99-runtime-Time-O(n)-Space-O(1)-with-inline-analysis | class Solution:
def findNumbers(self, nums: List[int]) -> int:
# Space O(1)
output = 0
# Time O(n)
for digit in nums:
# Convert int to str then calculate length and use modulus to check if even
if len(str(digit)) % 2 == 0:
output += 1
... | find-numbers-with-even-number-of-digits | Python3: 99% runtime, Time O(n) Space O(1) with inline analysis | dentedghost | 1 | 124 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,257 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2846973/Python-multiple-solutions | class Solution:
def findNumbers(self, nums: List[int]) -> int:
output = 0
for integers in nums:
even = 0
while integers != 0:
integers //= 10
even += 1
if even % 2 == 0:
output += 1
... | find-numbers-with-even-number-of-digits | Python multiple solutions | yijiun | 0 | 1 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,258 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2846973/Python-multiple-solutions | class Solution:
def findNumbers(self, nums: List[int]) -> int:
output = 0
for integers in nums:
if len(str(integers)) % 2 == 0:
output += 1
return output | find-numbers-with-even-number-of-digits | Python multiple solutions | yijiun | 0 | 1 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,259 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2846973/Python-multiple-solutions | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len([integers for integers in nums if len(str(integers)) % 2 == 0]) | find-numbers-with-even-number-of-digits | Python multiple solutions | yijiun | 0 | 1 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,260 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2838572/Python-one-line-using-Filter | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len(list(filter(lambda x: len(str(x)) % 2 == 0, nums))) | find-numbers-with-even-number-of-digits | Python one line using Filter | th4tkh13m | 0 | 1 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,261 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2819040/One-Liner-Python-Solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len([True for num in nums if len(str(num)) % 2 == 0]) | find-numbers-with-even-number-of-digits | One-Liner Python Solution | PranavBhatt | 0 | 2 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,262 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2809948/Python-or-One-liner | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum(1 for num in nums if len(str(num))%2 == 0) | find-numbers-with-even-number-of-digits | Python | One liner | pawangupta | 0 | 3 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,263 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2806674/Python3-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for num in nums:
if (len(str(num)) % 2 == 0):
count += 1
return count | find-numbers-with-even-number-of-digits | Python3 solution | SupriyaArali | 0 | 5 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,264 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2800390/python3-brute-force | class Solution:
def findNumbers(self, nums: List[int]) -> int:
result = 0
for x in nums:
count = 0
while x != 0:
x = x//10
count += 1
#print('count',count)
if count % 2 == 0:
result += 1
... | find-numbers-with-even-number-of-digits | python3 brute force | BhavyaBusireddy | 0 | 2 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,265 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2754812/Python3-Solution-oror-85-Faster-oror-Easy | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for i in nums:
if len(str(i)) % 2 == 0:
count += 1
return count | find-numbers-with-even-number-of-digits | Python3 Solution || 85% Faster || Easy | shashank_shashi | 0 | 2 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,266 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2739915/Python-3-Solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
arr = [len(str(x))%2 for x in nums]
return len(arr) - sum(arr) | find-numbers-with-even-number-of-digits | Python 3 Solution | mati44 | 0 | 3 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,267 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2731477/Python-solution-O(1)-space | class Solution:
def findNumbers(self, nums: List[int]) -> int:
for i in range(len(nums)):
nums[i] = len(str(nums[i])) % 2 == 0
return sum(nums) | find-numbers-with-even-number-of-digits | Python solution O(1) space | manufesto | 0 | 3 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,268 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2711771/Python3-99-Straightforward-using-strings | class Solution:
def findNumbers(self, nums: List[int]) -> int:
output = 0
for n in nums:
if len(str(n)) % 2 == 0:
output += 1
return output | find-numbers-with-even-number-of-digits | [Python3] 99% Straightforward using strings | connorthecrowe | 0 | 2 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,269 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2689783/Python-(traditional-approach) | class Solution:
def findNumbers(self, nums: List[int]) -> int:
k=0
nums=map(str,nums)
for x in nums:
if len(x)%2==0:
k=k+1
return k | find-numbers-with-even-number-of-digits | Python (traditional approach) | Leox2022 | 0 | 3 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,270 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2674718/Python-without-convert-int-to-str | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count_even = 0
for num in nums:
count = 0
while(num > 0):
num //= 10
count += 1
if count % 2 == 0:
count_even += 1
return count_... | find-numbers-with-even-number-of-digits | ✔️ Python without convert int to str | QuiShimo | 0 | 16 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,271 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2673910/Python-Simple-one-Line-code | class Solution:
def findNumbers(self, nums: List[int]) -> int:
cnt=0
cnt = len([cnt for i in nums if len(str(i))%2 == 0])
return cnt | find-numbers-with-even-number-of-digits | Python Simple one Line code | shubhamshinde245 | 0 | 4 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,272 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2657812/Python-oror-Easily-Understood-oror-Faster-than-96-oror-Fast | class Solution:
def findNumbers(self, nums: List[int]) -> int:
ans = 0
for i in nums:
if len(str(i))%2==0:
ans+=1
return ans | find-numbers-with-even-number-of-digits | 🔥 Python || Easily Understood ✅ || Faster than 96% || Fast | rajukommula | 0 | 29 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,273 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2652520/O(n)-Easy-Python-single-line-solution-using-%22map%22-and-%22lambda-function%22 | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum(map(lambda x : x%2==0, map(len, map(str, nums)))) | find-numbers-with-even-number-of-digits | O(n) Easy Python single line solution using "map" and "lambda function" | RoyaLotfi | 0 | 1 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,274 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2455245/Simple-oror-Python3-oror-Beats-97 | class Solution:
def findNumbers(self, nums: List[int]) -> int:
nums = list(map(str,nums))
res = 0
for i in nums:
if len(i) % 2 == 0:
res += 1
return res | find-numbers-with-even-number-of-digits | Simple || Python3 || Beats 97 % | irapandey | 0 | 58 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,275 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2449840/Simple-and-Easy-solution-or-Python-or-Easy-understanding | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for ele in nums:
if len(str(ele))%2 == 0:
count+=1
return count | find-numbers-with-even-number-of-digits | Simple & Easy solution | Python | Easy-understanding | PratyayMondal | 0 | 24 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,276 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2431626/Python-solution-using-math.log10() | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for i in nums:
digits_after_log = math.log10(i)
floor_log_num = math.floor(digits_after_log)
if floor_log_num > 0 and floor_log_num % 2 != 0:
count += 1
return count | find-numbers-with-even-number-of-digits | Python solution using math.log10() | samanehghafouri | 0 | 19 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,277 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2400966/Python3-Easy-One-Liner | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum([len(str(num)) % 2 == 0 for num in nums]) | find-numbers-with-even-number-of-digits | [Python3] Easy One-Liner | ivnvalex | 0 | 33 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,278 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2361933/Python-Solution-Without-Converting-to-String | class Solution:
def hasEvenDigits(self, num) -> int:
if num < pow(10, 1):
return False
elif num < pow(10,2):
return True
elif num < pow(10,3):
return False
elif num < pow(10,4):
return True
elif num < pow(10,5):
retu... | find-numbers-with-even-number-of-digits | Python Solution Without Converting to String | APet99 | 0 | 34 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,279 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2311339/Easy-to-understand-Python-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count_even = 0
for num in nums:
if len(str(num)) % 2 == 0:
count_even += 1
return count_even | find-numbers-with-even-number-of-digits | Easy to understand Python solution | Balance-Coffee | 0 | 54 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,280 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2290335/Python-One-Liner-72-ms-code | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len([x for x in nums if len(str(x))%2 == 0]) | find-numbers-with-even-number-of-digits | Python One Liner 72 ms code | Yodawgz0 | 0 | 51 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,281 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2169134/Simple-python3-solution-using-int-to-string-conversion | class Solution:
def findNumbers(self, nums: List[int]) -> int:
l = []
for i in nums:
if (len(str(i)))%2==0:
l.append(i)
return (len(l)) | find-numbers-with-even-number-of-digits | Simple python3 solution using int to string conversion | psnakhwa | 0 | 31 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,282 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2092106/PYTHON-or-Super-simple-python-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
res = 0
for i in range(len(nums)):
if len(str(nums[i])) % 2 == 0:
res += 1
return res | find-numbers-with-even-number-of-digits | PYTHON | Super simple python solution | shreeruparel | 0 | 54 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,283 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/2028129/Pythonic-clean-solution | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return len([x for x in nums if len(str(x))%2==0]) | find-numbers-with-even-number-of-digits | Pythonic clean solution | StikS32 | 0 | 59 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,284 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1927863/easy-python-code | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for i in nums:
if len(str(i))%2 == 0:
count += 1
return count | find-numbers-with-even-number-of-digits | easy python code | dakash682 | 0 | 58 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,285 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1918253/Python-Math-approach-%2B-String-conversion-or-Clean-and-Simple-or-One-Liner | class Solution:
def findNumbers(self, nums):
def getNumOfDigits(x): return len(str(x))
def isEven(x): return x % 2 == 0
return sum(isEven(getNumOfDigits(x)) for x in nums) | find-numbers-with-even-number-of-digits | Python - Math approach + String conversion | Clean and Simple | One-Liner | domthedeveloper | 0 | 67 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,286 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1918253/Python-Math-approach-%2B-String-conversion-or-Clean-and-Simple-or-One-Liner | class Solution:
def findNumbers(self, nums):
return sum(len(str(x))%2==0 for x in nums) | find-numbers-with-even-number-of-digits | Python - Math approach + String conversion | Clean and Simple | One-Liner | domthedeveloper | 0 | 67 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,287 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1918253/Python-Math-approach-%2B-String-conversion-or-Clean-and-Simple-or-One-Liner | class Solution:
def findNumbers(self, nums):
def getNumOfDigits(x): return floor(log10(x))+1
def isEven(x): return x % 2 == 0
return sum(isEven(getNumOfDigits(x)) for x in nums) | find-numbers-with-even-number-of-digits | Python - Math approach + String conversion | Clean and Simple | One-Liner | domthedeveloper | 0 | 67 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,288 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1918253/Python-Math-approach-%2B-String-conversion-or-Clean-and-Simple-or-One-Liner | class Solution:
def findNumbers(self, nums):
return sum((floor(log10(x))+1)%2==0 for x in nums) | find-numbers-with-even-number-of-digits | Python - Math approach + String conversion | Clean and Simple | One-Liner | domthedeveloper | 0 | 67 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,289 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1884262/Python-solution-by-converting-to-string | class Solution:
def findNumbers(self, nums: List[int]) -> int:
count = 0
for i in nums:
if len(str(i)) % 2 == 0:
count += 1
return count | find-numbers-with-even-number-of-digits | Python solution by converting to string | alishak1999 | 0 | 42 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,290 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1852961/1-Line-Python-Solution-oror-87-Faster-oror-Memory-less-than-72 | class Solution:
def findNumbers(self, nums: List[int]) -> int:
return sum([1 for num in nums if len(str(num))%2==0]) | find-numbers-with-even-number-of-digits | 1-Line Python Solution || 87% Faster || Memory less than 72% | Taha-C | 0 | 76 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,291 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1802187/Python3-easy-to-read-beats-97%2B | class Solution:
def findNumbers(self, nums: List[int]) -> int:
nums = list(map(str,nums))
count = 0
for num in nums:
if len(num)%2 == 0:
count += 1
return count | find-numbers-with-even-number-of-digits | Python3 easy-to-read beats 97+% | eating | 0 | 69 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,292 |
https://leetcode.com/problems/find-numbers-with-even-number-of-digits/discuss/1669938/Time-consuming-python-solution | class Solution(object):
def findNumbers(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
#iniializing the counter
counter = 0
for i in nums:
#counting the digits in the number
count = 0
while (i > 0):
i... | find-numbers-with-even-number-of-digits | Time consuming python solution | ebrahim007 | 0 | 44 | find numbers with even number of digits | 1,295 | 0.77 | Easy | 19,293 |
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/discuss/785364/O(N-log(N))-time-and-O(N)-space-Python3-using-Hashmap-and-lists | class Solution:
def isPossibleDivide(self, nums: List[int], k: int) -> bool:
hand = nums
W = k
if not hand and W > 0:
return False
if W > len(hand):
return False
if W == 0 or W == 1:
return True
expectation_map = {}
# self.... | divide-array-in-sets-of-k-consecutive-numbers | O(N log(N)) time and O(N) space- Python3 using Hashmap and lists | prajwalpv | 1 | 169 | divide array in sets of k consecutive numbers | 1,296 | 0.566 | Medium | 19,294 |
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/discuss/2837249/python-super-easy-greedy-using-hash-map | class Solution:
def isPossibleDivide(self, nums: List[int], k: int) -> bool:
if len(nums) % k != 0:
return False
count = collections.Counter(nums)
count = dict(sorted(count.items()))
print(count)
while count:
start_key = list(count.keys())[0]
... | divide-array-in-sets-of-k-consecutive-numbers | python super easy greedy using hash map | harrychen1995 | 0 | 3 | divide array in sets of k consecutive numbers | 1,296 | 0.566 | Medium | 19,295 |
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/discuss/2523049/Python-easy-to-read-and-understand-or-hashmap | class Solution:
def isPossibleDivide(self, nums: List[int], k: int) -> bool:
n = len(nums)
if n%k != 0:
return False
d = {}
for num in nums:
d[num] = d.get(num, 0) + 1
while d:
mn = min(d.keys())
for i in range... | divide-array-in-sets-of-k-consecutive-numbers | Python easy to read and understand | hashmap | sanial2001 | 0 | 71 | divide array in sets of k consecutive numbers | 1,296 | 0.566 | Medium | 19,296 |
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/discuss/462636/Python3-Hash-function-and-DFS-solution-with-explanation | class Solution:
def isPossibleDivide(self, nums: List[int], k: int) -> bool:
def dfs_util(num_counts, val, left):
if left == 0:
return True
if val not in num_counts:
return False
else:
num_counts[val] -= 1
... | divide-array-in-sets-of-k-consecutive-numbers | Python3 Hash function and DFS solution with explanation | geekcoder1989 | 0 | 75 | divide array in sets of k consecutive numbers | 1,296 | 0.566 | Medium | 19,297 |
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/discuss/457638/Python-3-(seven-lines) | class Solution:
def isPossibleDivide(self, N: List[int], k: int) -> bool:
L, C = len(N), collections.Counter(N)
for i in range(L//k):
m = min(C.keys())
for j in range(m,m+k):
if C[j] > 1: C[j] -= 1
else: del C[j]
return not (C or L % k)... | divide-array-in-sets-of-k-consecutive-numbers | Python 3 (seven lines) | junaidmansuri | 0 | 352 | divide array in sets of k consecutive numbers | 1,296 | 0.566 | Medium | 19,298 |
https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring/discuss/1905801/python-easy-approach | class Solution:
def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:
s1 = []
count ={}
while minSize <= maxSize:
for i in range(0,len(s)):
if (i+ minSize) <=len(s) and len(set(s[i: i+ minSize])) <= maxLetters:
s1.appen... | maximum-number-of-occurrences-of-a-substring | python easy approach | hari07 | 4 | 286 | maximum number of occurrences of a substring | 1,297 | 0.52 | Medium | 19,299 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.