Skip to content

Commit

Permalink
Merge pull request #747 from sungjinwi/main
Browse files Browse the repository at this point in the history
[sungjinwi] Week 2
  • Loading branch information
SamTheKorean authored Dec 22, 2024
2 parents 2099534 + e81a0e3 commit fd7d604
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
21 changes: 21 additions & 0 deletions climbing-stairs/sungjinwi.py
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)
34 changes: 34 additions & 0 deletions valid-anagram/sungjinwi.py
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)

0 comments on commit fd7d604

Please sign in to comment.