File tree Expand file tree Collapse file tree 5 files changed +88
-0
lines changed
longest-substring-without-repeating-characters Expand file tree Collapse file tree 5 files changed +88
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ def numDecodings (self , s : str ) -> int :
3+
Original file line number Diff line number Diff line change 1+ """
2+ Blind75 - length of longest substring without repeating characters
3+ https://leetcode.com/problems/longest-substring-without-repeating-characters/
4+ μκ°λ³΅μ‘λ : O(n)
5+ 곡κ°λ³΅μ‘λ : O(min(m, n)) (λ¬Έμ μ§ν© char_index_mapμ ν¬κΈ°, μ΅λλ n = len(s))
6+ νμ΄ : μ¬λΌμ΄λ© μλμ° κΈ°λ²μ μ¬μ©ν λ¬Έμμ΄ μν
7+ """
8+
9+
10+ class Solution :
11+ def lengthOfLongestSubstring (self , s : str ) -> int :
12+ max_count = 0
13+ start = 0
14+ char_index_map = {}
15+
16+ for i , char in enumerate (s ):
17+ if char in char_index_map and char_index_map [char ] >= start :
18+ start = char_index_map [char ] + 1
19+ char_index_map [char ] = i
20+ else :
21+ char_index_map [char ] = i
22+ max_count = max (max_count , i - start + 1 )
23+
24+ return max_count
25+
Original file line number Diff line number Diff line change 1+ """
2+ Blind75 - 5. Maximum Subarray
3+ LeetCode Problem Link: https://leetcode.com/problems/maximum-subarray/
4+
5+ ν΅κ³Όλ νλλ° μκ°λ³΅μ‘λ O(n^2)λΌμ μ’ μμ½λ€...ν¬ν¬μΈν°λ‘ ν μλ μμ κ±° κ°μλ°...
6+ """
7+ from typing import List
8+
9+ class Solution :
10+ def maxSubArray (self , nums : List [int ]) -> int :
11+ max_total = nums [0 ]
12+
13+ for s in range (len (nums )):
14+ total = 0
15+ for e in range (s , len (nums )):
16+ total += nums [e ]
17+ if total > max_total :
18+ max_total = total
19+ return max_total
20+
Original file line number Diff line number Diff line change 1+ """
2+ Blind75 - Number of 1 Bits
3+ https://leetcode.com/problems/number-of-1-bits/
4+ μκ°λ³΅μ‘λ : O(log n)
5+ 곡κ°λ³΅μ‘λ : O(1)
6+
7+ νμ΄ :
8+ νμ΄μ¬μ λ΄μ₯ν¨μ bin() -> O(log n)
9+ λ¬Έμμ΄ λ©μλ count() -> O(log n)
10+
11+ """
12+
13+ class Solution :
14+ def hammingWeight (self , n : int ) -> int :
15+ return str (bin (n )).count ('1' )
16+
17+
Original file line number Diff line number Diff line change 1+ """
2+ Blind75 - Valid Palindrome
3+ https://leetcode.com/problems/valid-palindrome/
4+
5+ μκ°λ³΅μ‘λ O(n), 곡κ°λ³΅μ‘λ O(n)
6+
7+ isalnum() ν¨μλ μκ°λ³΅μ‘λ O(1)μ΄λ―λ‘ νν°λ§νλ κ³Όμ λ O(n)μ΄λ€.
8+ [::-1] μ¬λΌμ΄μ±λ O(n)μ΄λ€.
9+ λ°λΌμ μ 체 μκ°λ³΅μ‘λλ O(n)μ΄λ€.
10+
11+
12+ Runtime Beats
13+ 7ms 82.67%
14+
15+ Memory Beats
16+ 23.14 MB 17.23%
17+ """
18+
19+ class Solution :
20+ def isPalindrome (self , s : str ) -> bool :
21+ filtered_s = '' .join (char .lower () for char in s if char .isalnum ())
22+ return filtered_s == filtered_s [::- 1 ]
23+
You canβt perform that action at this time.
0 commit comments