Repository navigation
[Chaewon-Park-STUDY] WEEK 03 Solutions - #2952
Conversation
|
🤖 AI 리뷰(알고리즘 패턴, 시간/공간 복잡도, 학습 현황) 결과는 Checks 탭에서 볼 수 있어요. |
Implement palindrome check for a given string.
Implement maxSubArray method to find maximum subarray sum.
| def hammingWeight(self, n: int) -> int: | ||
| num = 0 | ||
| while n> 0: | ||
| num += n & 1 # 가장 우측 비트가 1이면 +1 (n % 2) |
There was a problem hiding this comment.
n & 1 해서 바로 더하면 카운팅되는군요. if n&1: 이면 더해줬는데 이렇게 바로 생각은 못했네요. 잘 참고했습니다. 👍
| @@ -0,0 +1,9 @@ | |||
| class Solution: | |||
There was a problem hiding this comment.
투포인터로 하면 공간복잡도 O(1)으로 풀이 가능하더군요. 참고바랍니다.
There was a problem hiding this comment.
투포인터 기법으로 다시 한번 풀어보겠습니다! 감사합니다🙂
| answer = [] | ||
| path = [] | ||
|
|
||
| def dfs(start, remain): |
There was a problem hiding this comment.
저는 sum을 파라미터로 가지고 다녔는데 remain으로 하니까 더 깔끔하게 풀이가 되는군요. 참고가 되었습니다.
There was a problem hiding this comment.
오 currentsum으로 따로 변수를 빼니 더 명시적인 것 같습니다!
| @@ -0,0 +1,28 @@ | |||
| # 비트 풀이 | |||
There was a problem hiding this comment.
비트 연산으로 푸셨군요! 아래 주석을 보니 첫번째 풀이는 2로 나누는 연산을 하셨네요
두 개의 풀이를 비교할 수 있게 올려주셔서 잘 보고 갑니다
| dp=[0 for _ in range(k+1)] | ||
| dp[0]=1 |
There was a problem hiding this comment.
nit: = 연산 좌우에 공백은 다른 풀이와 동일하게 일치 시켜주면 좋을거 같네요!
| if not s[left].isalnum(): | ||
| left += 1 | ||
| continue | ||
| if not s[right].isalnum(): | ||
| right -= 1 | ||
| continue |
| def maxSubArray(self, nums: list[int]) -> int: | ||
| k=len(nums) | ||
| # Time: O(n) - 배열 loop, Space: O(1) | ||
| prev=nums[0] #이전까지의 합 중 max |
There was a problem hiding this comment.
"이전까지의 합 중 max" 라는 값이니 변수명도 의미를 담으면 좋을 거 같습니다.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!