-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #747 from sungjinwi/main
[sungjinwi] Week 2
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
''' | ||
- λ¬λ μ€ν°λ νμ΄ μ°Έκ³ ν¨ | ||
νμ΄ : | ||
nλ²μ§Έ κ³λ¨μ μ€λ₯΄κΈ° μν΄μλ n-1 λλ n-2μ μλ€κ° μ¬λΌμ€λ μ λ°μ μμΌλ―λ‘ f(n-1) + f(n-2)μ κ° | ||
dp λ°°μ΄λ‘ ν μλ μμ§λ§ λ κ°μ λ³μμ μ λ°μ΄νΈ νλ μμΌλ‘ νμ΄ | ||
TC : | ||
forλ¬ΈμΌλ‘ μΈν΄ O(N) | ||
SC : | ||
O(1) | ||
''' | ||
|
||
class Solution: | ||
def climbStairs(self, n: int) -> int: | ||
if n < 3 : | ||
return (n) | ||
prv, cur = 1, 2 | ||
for _ in range(3, n + 1) : | ||
prv, cur = cur, prv + cur | ||
return (cur) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
''' | ||
νμ΄ : | ||
λ¬Έμμ΄ sμμ λ¬Έμκ° λμ¬ λλ§λ€ λμ λ리μ μ μ₯νκ³ μ«μ μ¦κ° | ||
λ¬Έμμ΄ tμμ λμΌν λ¬Έμκ° λμ¬ λλ§λ€ μ«μ κ°μμν€κ³ 0λλ©΄ λμ λ리μμ μ κ±° | ||
λμ λ리μ μλ λ¬Έμκ° λμ€κ±°λ μμ μ΄ λλ ν λμ λλ¦¬κ° λΉμ΄μμ§ μλ€λ©΄ False | ||
TC : | ||
forλ¬Έ λλ² λκΈ° λλ¬Έμ O(N) | ||
SC : | ||
λμ λ리 ν λΉνλ λ©λͺ¨λ¦¬λ₯Ό κ³ λ €νλ©΄ O(N) | ||
''' | ||
|
||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
if len(s) != len(t) : | ||
return (False) | ||
dic = {} | ||
for char in s : | ||
if char in dic : | ||
dic[char] += 1 | ||
else : | ||
dic[char] = 1 | ||
for char in t : | ||
if char in dic : | ||
dic[char] -= 1 | ||
if dic[char] == 0 : | ||
dic.pop(char) | ||
else : | ||
return (False) | ||
if dic : | ||
return (False) | ||
else : | ||
return (True) |