File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
longest-substring-without-repeating-characters Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ """
3+ a => μΈνΈ {}μ a μμ
4+ ab => μΈνΈ {a}μ b μμ
5+ aba => μΈνΈ {a, b}μ a μμ => μ€λ³΅
6+ abac => λ μ΄μ κ³ λ € κ°μΉ μμ
7+ """
8+ def lengthOfLongestSubstring (self , s : str ) -> int :
9+ max_len = 0
10+ for start in range (len (s )):
11+ chars = set ()
12+ for end in range (start , len (s )):
13+ if s [end ] in chars :
14+ break
15+ chars .add (s [end ])
16+ max_len = max (end - start + 1 , max_len )
17+ return max_len
Original file line number Diff line number Diff line change 1+ # Definition for singly-linked list.
2+ # class ListNode:
3+ # def __init__(self, val=0, next=None):
4+ # self.val = val
5+ # self.next = next
6+ class Solution :
7+ """
8+ λ§ν¬λ 리μ€νΈ νμ΅μ λ°λ‘ ν΄μΌν νμμ±μ΄ μμ
9+ """
10+ def reverseList (self , head : Optional [ListNode ]) -> Optional [ListNode ]:
11+ stack = []
12+ node = head
13+ while node :
14+ stack .append (node )
15+ node = node .next
16+
17+ dummy = ListNode ()
18+ output = dummy
19+ while stack :
20+ output .next = stack .pop ()
21+ output = output .next
22+
23+ output .next = None
24+ return dummy .next
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def setZeroes (self , matrix : List [List [int ]]) -> None :
3+ """
4+ Do not return anything, modify matrix in-place instead.
5+ """
6+ zero = []
7+ for i in range (len (matrix )):
8+ for j in range (len (matrix [0 ])):
9+ if matrix [i ][j ] == 0 :
10+ zero .append ((i , j ))
11+
12+ for x , y in zero :
13+ for i in range (len (matrix [0 ])):
14+ matrix [x ][i ] = 0
15+ for i in range (len (matrix )):
16+ matrix [i ][y ] = 0
Original file line number Diff line number Diff line change 1+ class Solution :
2+ """
3+ dfsλ‘ νλ©΄ λ κ²μ΄λΌκ³ μκ°μ νμ§λ§ μ΄μ λ¬Έμ μ κ°μ λ°©μμΌ μ€ μμλλ° μ΄λ¬ν λ°©μμ΄ μλ κ²μ μμμ
4+ """
5+ # def uniquePaths(self, m: int, n: int) -> int:
6+ # def dfs(x, y):
7+ # if x == m - 1 and y == n - 1:
8+ # return 1
9+ # if x >= m or y >= n:
10+ # return 0
11+
12+ # return dfs(x + 1, y) + dfs(x, y + 1)
13+
14+ # return dfs(0, 0)
15+
16+ def uniquePaths (self , m : int , n : int ) -> int :
17+ dp = [[1 ] * n for _ in range (m )]
18+
19+ for row in range (1 , m ):
20+ for col in range (1 , n ):
21+ dp [row ][col ] = dp [row - 1 ][col ] + dp [row ][col - 1 ]
22+
23+ return dp [- 1 ][- 1 ]
You canβt perform that action at this time.
0 commit comments