From 1e8d5cf7557cbc1347b9f49e381739a4b485b132 Mon Sep 17 00:00:00 2001 From: sungjinwi <0202wsj@gmail.com> Date: Mon, 16 Dec 2024 22:11:36 +0900 Subject: [PATCH 1/3] FEAT : valid-anagram solution --- valid-anagram/sungjinwi.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 valid-anagram/sungjinwi.py diff --git a/valid-anagram/sungjinwi.py b/valid-anagram/sungjinwi.py new file mode 100644 index 000000000..3f58cdede --- /dev/null +++ b/valid-anagram/sungjinwi.py @@ -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) From 2415f2d93fdf165f00c273c07ff5a2aee79f2537 Mon Sep 17 00:00:00 2001 From: sungjinwi <0202wsj@gmail.com> Date: Wed, 18 Dec 2024 01:18:37 +0900 Subject: [PATCH 2/3] climbing-stairs solution --- climbing-stairs/sungjinwi.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 climbing-stairs/sungjinwi.py diff --git a/climbing-stairs/sungjinwi.py b/climbing-stairs/sungjinwi.py new file mode 100644 index 000000000..686309aaa --- /dev/null +++ b/climbing-stairs/sungjinwi.py @@ -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) \ No newline at end of file From e81a0e3df23a4c72b9c6495d36e9f39a09b26261 Mon Sep 17 00:00:00 2001 From: sungjinwi <0202wsj@gmail.com> Date: Thu, 19 Dec 2024 13:16:28 +0900 Subject: [PATCH 3/3] Fix : climbing-stairs line lint fix --- climbing-stairs/sungjinwi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climbing-stairs/sungjinwi.py b/climbing-stairs/sungjinwi.py index 686309aaa..d1f7f2f83 100644 --- a/climbing-stairs/sungjinwi.py +++ b/climbing-stairs/sungjinwi.py @@ -18,4 +18,4 @@ def climbStairs(self, n: int) -> int: prv, cur = 1, 2 for _ in range(3, n + 1) : prv, cur = cur, prv + cur - return (cur) \ No newline at end of file + return (cur)