Skip to content

Commit fd7d604

Browse files
authored
Merge pull request #747 from sungjinwi/main
[sungjinwi] Week 2
2 parents 2099534 + e81a0e3 commit fd7d604

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

β€Žclimbing-stairs/sungjinwi.pyβ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
- λ‹¬λ ˆμŠ€ν„°λ”” 풀이 참고함
3+
풀이 :
4+
n번째 계단을 였λ₯΄κΈ° μœ„ν•΄μ„œλŠ” n-1 λ˜λŠ” n-2에 μžˆλ‹€κ°€ μ˜¬λΌμ˜€λŠ” 수 밖에 μ—†μœΌλ―€λ‘œ f(n-1) + f(n-2)의 κ°’
5+
dp λ°°μ—΄λ‘œ ν’€ μˆ˜λ„ μžˆμ§€λ§Œ 두 개의 λ³€μˆ˜μ— μ—…λ°μ΄νŠΈ ν•˜λŠ” μ‹μœΌλ‘œ 풀이
6+
7+
TC :
8+
for문으둜 인해 O(N)
9+
10+
SC :
11+
O(1)
12+
'''
13+
14+
class Solution:
15+
def climbStairs(self, n: int) -> int:
16+
if n < 3 :
17+
return (n)
18+
prv, cur = 1, 2
19+
for _ in range(3, n + 1) :
20+
prv, cur = cur, prv + cur
21+
return (cur)

β€Žvalid-anagram/sungjinwi.pyβ€Ž

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
풀이 :
3+
λ¬Έμžμ—΄ sμ—μ„œ λ¬Έμžκ°€ λ‚˜μ˜¬ λ•Œλ§ˆλ‹€ λ”•μ…”λ„ˆλ¦¬μ— μ €μž₯ν•˜κ³  숫자 증가
4+
λ¬Έμžμ—΄ tμ—μ„œ λ™μΌν•œ λ¬Έμžκ°€ λ‚˜μ˜¬ λ•Œλ§ˆλ‹€ 숫자 κ°μ†Œμ‹œν‚€κ³  0되면 λ”•μ…”λ„ˆλ¦¬μ—μ„œ 제거
5+
λ”•μ…”λ„ˆλ¦¬μ— μ—†λŠ” λ¬Έμžκ°€ λ‚˜μ˜€κ±°λ‚˜ μž‘μ—…μ΄ λλ‚œ ν›„ λ”•μ…”λ„ˆλ¦¬κ°€ λΉ„μ–΄μžˆμ§€ μ•Šλ‹€λ©΄ False
6+
7+
TC :
8+
forλ¬Έ λ‘λ²ˆ 돌기 λ•Œλ¬Έμ— O(N)
9+
10+
SC :
11+
λ”•μ…”λ„ˆλ¦¬ ν• λ‹Ήν•˜λŠ” λ©”λͺ¨λ¦¬λ₯Ό κ³ λ €ν•˜λ©΄ O(N)
12+
'''
13+
14+
class Solution:
15+
def isAnagram(self, s: str, t: str) -> bool:
16+
if len(s) != len(t) :
17+
return (False)
18+
dic = {}
19+
for char in s :
20+
if char in dic :
21+
dic[char] += 1
22+
else :
23+
dic[char] = 1
24+
for char in t :
25+
if char in dic :
26+
dic[char] -= 1
27+
if dic[char] == 0 :
28+
dic.pop(char)
29+
else :
30+
return (False)
31+
if dic :
32+
return (False)
33+
else :
34+
return (True)

0 commit comments

Comments
Β (0)