Posting/260528 - #76
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds new markdown documentation summarizing problem-solving patterns and LeetCode 206 (Reverse Linked List) solutions in JavaScript, alongside minor formatting updates to LeetCode 98. The reviewer suggested optimizing the second solution for LeetCode 206 to perform an in-place reversal, which reduces the space complexity from O(n) to O(1), and recommended updating the complexity explanation accordingly.
| var reverseList = function (head) { | ||
| // input값 없을때 처리 | ||
| if (!head) { | ||
| return head; | ||
| } | ||
|
|
||
| // 최적화 : 조회하자마자 바로넣으면 뒤집어짐 | ||
| let current = head; | ||
| let newHead = null; | ||
|
|
||
| while (current) { | ||
| newHead = new ListNode(current.val, newHead); | ||
| current = current.next; | ||
| } | ||
|
|
||
| return newHead; | ||
| }; |
There was a problem hiding this comment.
현재 작성하신 '내풀이 2차' 방식은 매번 new ListNode를 생성하여 새로운 노드를 메모리에 할당하고 있습니다. 이 방식은 공간 복잡도가
기존 노드의 next 포인터만 변경하는 방식으로 구현하면 추가적인 노드 생성 없이 **공간 복잡도
| var reverseList = function (head) { | |
| // input값 없을때 처리 | |
| if (!head) { | |
| return head; | |
| } | |
| // 최적화 : 조회하자마자 바로넣으면 뒤집어짐 | |
| let current = head; | |
| let newHead = null; | |
| while (current) { | |
| newHead = new ListNode(current.val, newHead); | |
| current = current.next; | |
| } | |
| return newHead; | |
| }; | |
| var reverseList = function (head) { | |
| let prev = null; | |
| let current = head; | |
| while (current) { | |
| const nextTemp = current.next; | |
| current.next = prev; | |
| prev = current; | |
| current = nextTemp; | |
| } | |
| return prev; | |
| }; |
| - 시간 복잡도: O(n) — current로 리스트를 한 번만 순회하며 prepend (1차 대비 순회 횟수·상수 계수 감소) | ||
| - 공간 복잡도: O(n) — 보조 배열은 없지만 새 ListNode를 n개 생성 (포인터 변수 current, newHead만 보면 O(1), 노드 할당까지 포함하면 O(n)) |
There was a problem hiding this comment.
제자리(In-place) 포인터 역전 방식을 사용할 경우, 추가적인 노드 생성이 없으므로 공간 복잡도를
| - 시간 복잡도: O(n) — current로 리스트를 한 번만 순회하며 prepend (1차 대비 순회 횟수·상수 계수 감소) | |
| - 공간 복잡도: O(n) — 보조 배열은 없지만 새 ListNode를 n개 생성 (포인터 변수 current, newHead만 보면 O(1), 노드 할당까지 포함하면 O(n)) | |
| - 시간 복잡도: O(n) — 리스트를 한 번만 순회하며 포인터를 변경 | |
| - 공간 복잡도: O(1) — 기존 노드의 포인터만 변경하므로 추가적인 메모리를 사용하지 않음 |
PR전 코드 퀄리티 체크하기
작업내용
🔍 가독성 (Readability) CHECK
명명 규칙
const ANIMATION_DELAY_MS = 300형태로 의미 있는 이름 사용const isValidUser = user.age >= 18 && user.isVerifieduserData→authenticatedUser,list→activeUserList구조 및 구성
추상화 및 분리
AuthGuard컴포넌트ViewerSubmitButton,AdminSubmitButton로 역할별 분리🎯 예측 가능성 (Predictability) CHECK
반환 타입 일관성
UseQueryResult<T, Error>일관 사용{ ok: boolean; reason?: string }형태 일관 사용단일 책임 원칙
fetchBalance()가 로깅 등 부수효과 없이 balance만 반환명확한 명명
http.get()→httpService.getWithAuth()useModal()→useConfirmationModal()🔗 응집도 (Cohesion) CHECK
도메인별 구성
domains/user/,domains/product/폼 응집도
⚡ 결합도 (Coupling) CHECK
상태 관리 범위
useCardIdQueryParam()같은 focused hook 사용Props Drilling 제거
추상화 수준
📋 추가 CHECK
성능 고려사항
useCallback,useMemo적절 사용타입 안정성
테스트 가능성
문서화
🎨 코드 스타일 CHECK