Skip to content

Commit 0b9dc57

Browse files
author
sangbeenmoon
committed
solved set-matrix-zeros, tried longest-substring-...
1 parent c4805c1 commit 0b9dc57

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s: str) -> int:
3+
4+
start = 0
5+
last_seen = {}
6+
answer = 0
7+
8+
for i,ch in enumerate(s):
9+
if ch in last_seen:
10+
if start < last_seen[ch]:
11+
start = last_seen[ch] + 1
12+
13+
last_seen[ch] = i
14+
answer = max(answer, i - start + 1)
15+
16+
return answer

set-matrix-zeroes/sangbeenmoon.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SC : O(m+n)
2+
3+
class Solution:
4+
def setZeroes(self, matrix: List[List[int]]) -> None:
5+
"""
6+
Do not return anything, modify matrix in-place instead.
7+
"""
8+
m,n = len(matrix), len(matrix[0])
9+
10+
row_dict = {}
11+
col_dict = {}
12+
13+
for r in range(m):
14+
for c in range(n):
15+
if matrix[r][c] == 0:
16+
row_dict[r] = True
17+
col_dict[c] = True
18+
19+
for r in range(m):
20+
for c in range(n):
21+
if r in row_dict or c in col_dict:
22+
matrix[r][c] = 0

0 commit comments

Comments
 (0)