Skip to content

Conversation

@imgolden77
Copy link
Contributor

@imgolden77 imgolden77 commented Jan 1, 2026

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR contains Week 8 algorithm problem solutions covering 7 different LeetCode-style problems. The solutions demonstrate understanding of various data structures and algorithms including stacks, linked lists, bit manipulation, string processing, and graph traversal.

  • Two implementations for valid-parentheses problem (initial and refactored)
  • Solutions for linked list reversal, bit reversal, and palindrome counting
  • Sliding window implementations for substring problems
  • Graph cloning using DFS with memoization

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
valid-parentheses/imgolden77.py Two implementations of parentheses validation using stack - first with explicit conditionals, second using dictionary mapping
reverse-linked-list/imgolden77.py Iterative linked list reversal using three pointers (prev, curr, post)
reverse-bits/imgolden77.py Bit manipulation solution to reverse 32-bit integer
palindromic-substrings/imgolden77.py Expand-around-center approach to count palindromic substrings
longest-substring-without-repeating-characters/imgolden77.py Two approaches - list-based and hash map-based sliding window
longest-repeating-character-replacement/imgolden77.py Sliding window with character frequency tracking
clone-graph/imgolden77.py DFS-based graph cloning with hash map for node mapping

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

elif i == ')':
if stack== []:
return False
elif stack[-1]== '(':
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around the equality operator. Should be 'stack[-1] == ' to match Python style conventions (PEP 8).

Copilot uses AI. Check for mistakes.
else:
return False
elif i == '}':
if stack== []:
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around the equality operator. Should be 'stack == []' to match Python style conventions (PEP 8).

Copilot uses AI. Check for mistakes.
elif i == '}':
if stack== []:
return False
elif stack[-1]== '{':
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around the equality operator. Should be 'stack[-1] == ' to match Python style conventions (PEP 8).

Copilot uses AI. Check for mistakes.
elif i == ']':
if stack == []:
return False
elif stack[-1]== '[':
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around the equality operator. Should be 'stack[-1] == ' to match Python style conventions (PEP 8).

Copilot uses AI. Check for mistakes.
if i in par_map.values():
stack.append(i)
elif i in par_map:
if not stack or stack[-1] !=par_map[i]:
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing around the inequality operator. Should be 'stack[-1] != par_map[i]' to match Python style conventions (PEP 8).

Suggested change
if not stack or stack[-1] !=par_map[i]:
if not stack or stack[-1] != par_map[i]:

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +24
for neighbors in curr_node.neighbors:
copy.neighbors.append(dfs(neighbors))
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 'neighbors' in the loop is misleading because it represents a single neighbor node, not multiple neighbors. It should be singular, like 'neighbor', to accurately reflect what it represents.

Suggested change
for neighbors in curr_node.neighbors:
copy.neighbors.append(dfs(neighbors))
for neighbor in curr_node.neighbors:
copy.neighbors.append(dfs(neighbor))

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +8
former= ['(', '{', '[']

for i in s:
if i in former:
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 'former' should be 'opening' or 'opening_brackets' to better describe its purpose. The name 'former' is ambiguous and doesn't clearly convey that it contains opening parentheses.

Suggested change
former= ['(', '{', '[']
for i in s:
if i in former:
opening_brackets = ['(', '{', '[']
for i in s:
if i in opening_brackets:

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +14
seen[char] = seen.get(char, 0) + 1
# what I wrote initially:
# if char not in seen:
# seen[char] = 1
# else:
# seen[char] += 1
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment appears to contain commented-out code.

Suggested change
seen[char] = seen.get(char, 0) + 1
# what I wrote initially:
# if char not in seen:
# seen[char] = 1
# else:
# seen[char] += 1
seen[char] = seen.get(char, 0) + 1 # update frequency of current character

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +37
class Solution:
def isValid(self, s: str) -> bool:
stack = []
former= ['(', '{', '[']

for i in s:
if i in former:
stack.append(i)
elif i == ')':
if stack== []:
return False
elif stack[-1]== '(':
stack.pop()
else:
return False
elif i == '}':
if stack== []:
return False
elif stack[-1]== '{':
stack.pop()
else:
return False
elif i == ']':
if stack == []:
return False
elif stack[-1]== '[':
stack.pop()
else:
return False


if stack == []:
return True
else:
return False

Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to 'Solution' is unnecessary as it is redefined before this value is used.

Suggested change
class Solution:
def isValid(self, s: str) -> bool:
stack = []
former= ['(', '{', '[']
for i in s:
if i in former:
stack.append(i)
elif i == ')':
if stack== []:
return False
elif stack[-1]== '(':
stack.pop()
else:
return False
elif i == '}':
if stack== []:
return False
elif stack[-1]== '{':
stack.pop()
else:
return False
elif i == ']':
if stack == []:
return False
elif stack[-1]== '[':
stack.pop()
else:
return False
if stack == []:
return True
else:
return False
# (obsolete implementation removed; see the Solution class below)

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +29
h = []
max_s = 0
for i in s:
if i not in h:
h.append(i)
else:
h=h[h.index(i)+1:]
h.append(i)
#I reset h=[] but it had problemswith the cases like "dvdf"
#So I modified it to h=h[h.index(i)+1:]
max_s = max(max_s, len(h))

return max_s

#O(N^2) time complexity due to "if i not in h" and O(min(m,n)) space complexity where m is the size of the charset and n is the size of the string s.

class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
seen = {}
start = 0
max_len = 0
for i, char in enumerate(s):
if char in seen and seen[char]>=start:
start= seen[char]+1
seen[char]=i
max_len = max(max_len, i - start +1)

Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to 'Solution' is unnecessary as it is redefined before this value is used.

Suggested change
h = []
max_s = 0
for i in s:
if i not in h:
h.append(i)
else:
h=h[h.index(i)+1:]
h.append(i)
#I reset h=[] but it had problemswith the cases like "dvdf"
#So I modified it to h=h[h.index(i)+1:]
max_s = max(max_s, len(h))
return max_s
#O(N^2) time complexity due to "if i not in h" and O(min(m,n)) space complexity where m is the size of the charset and n is the size of the string s.
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
seen = {}
start = 0
max_len = 0
for i, char in enumerate(s):
if char in seen and seen[char]>=start:
start= seen[char]+1
seen[char]=i
max_len = max(max_len, i - start +1)
seen = {}
start = 0
max_len = 0
for i, char in enumerate(s):
if char in seen and seen[char] >= start:
start = seen[char] + 1
seen[char] = i
max_len = max(max_len, i - start + 1)

Copilot uses AI. Check for mistakes.
@TonyKim9401
Copy link
Contributor

@DaleStudy 리뷰해줘

@dalestudy
Copy link
Contributor

dalestudy bot commented Jan 3, 2026

전체적으로 다양한 문제에 대해 깔끔하고 이해하기 쉬운 코드 구현이 돋보입니다. 다음은 몇 가지 건설적 피드백입니다.

  1. 시간/공간 복잡도 명시
    대부분의 솔루션에 적절한 복잡도 표기가 포함되어 있어 좋습니다. 특히 cloneGraph는 O(N+E), characterReplacement는 O(N), longestSubstringWithoutRepeatingCharacters는 O(N) 등 명확합니다. 다만, reverseBits는 "32번 반복"으로 정해진 고정 반복이기 때문에 O(1)임을 명확히 표기하는 것도 좋겠습니다.

  2. 복잡도 분석의 정확성

    • cloneGraph의 시간복잡도는 노드와 간선 수에 따라 정확하게 O(N+E)로 표기되어 적절합니다.
    • characterReplacement는 최대 문자 수(영어 알파벳 등)에 따라 O(1)라고 표기했는데, 문제의 입력 범위에 따라 다를 수 있으니, 일반적으로는 O(N)으로 보는 것도 좋습니다.
    • longestSubstringWithoutRepeatingCharacters의 두 구현 모두 시간 복잡도 표기가 적절하며, 해시맵을 활용한 버전이 O(N)임을 잘 언급하셨습니다.
  3. 접근법 제안

    • longestSubstringWithoutRepeatingCharacters의 두 번째 버전은 최적이며, 더 깔끔하고 효율적입니다. 만약 더 최적화하고 싶다면, 슬라이드윈도우 기법을 활용하는 것도 고려할 수 있습니다(이미 구현하셨지만, 설명에 추가하면 좋겠네요).
    • validParentheses는 스택을 이용한 표준 풀이로 적절하며, 딕셔너리 매핑을 활용한 두 번째 버전이 가독성도 좋고 효율적입니다.
  4. 가독성 및 스타일

    • cloneGraphdfs 내부에서 neighbors 변수 이름이 복수형인데, neighbor가 더 직관적입니다.
    • reverseList에서 if prev: 조건이 불필요하거나, 전체 구조를 더 깔끔하게 다듬을 수 있습니다. 예를 들어, prevNone일 때와 아닐 때를 구분하지 않고도 간단하게 구현 가능하며, while curr: 내부에서 curr.next 조작만으로도 충분합니다.
    • validParentheses의 두 번째 버전은 코드가 깔끔하고 직관적입니다. 다만, return not stack은 파이썬스럽고 좋은 표현입니다.
  5. 코드 스타일 및 베스트 프랙티스

    • cloneGraphNode 클래스는 주석으로 정의되어 있는데, 실제 사용 시 Node 클래스 정의가 필요하니, 그 부분도 포함하는 것이 좋겠습니다.
    • 모든 코드에 간단한 주석이 있어 이해를 돕고 있으며, PEP8 스타일도 준수되어 있습니다.
  6. 추가 제안

    • reverseBits는 비트 연산을 이용하는 좋은 방법입니다. 혹시 더 빠른 방법이나 캐시를 사용하는 방법도 고려해볼 수 있습니다(예: 분할 정복 방식).
    • reverseListprevcurr를 이용하는 표준 방법으로, 더 간단하게 while curr: 내부에서 curr.next, prev, curr = prev, curr, next_node 순으로 구현하는 것도 추천합니다.

전반적으로, 깔끔하고 효과적인 구현입니다. 약간의 스타일 개선과 더 명확한 복잡도 표기만 보완한다면 더욱 훌륭한 PR이 될 것 같습니다. 계속해서 좋은 코드 기대하겠습니다!

Copy link
Contributor

@TonyKim9401 TonyKim9401 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8주차 문제 풀이 고생하셨습니다.
연말&연초부터 여러 문제들 한번에 풀어주셨네요.
풀이들 모두 정석적으로 풀어주신것 같아습니다.
2026년 알고리즘 문제 풀이로 시작하신 만큼 커리어에서 원하는 쪽으로 더욱 승승장구 하시길 바라겠습니다.
9주차 문제풀이 파이팅입니다!

@TonyKim9401 TonyKim9401 merged commit a65e26d into DaleStudy:main Jan 3, 2026
9 checks passed
@github-project-automation github-project-automation bot moved this from Solving to Completed in 리트코드 스터디 6기 Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

2 participants