Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions missing-number/std-freejia.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int missingNumber(int[] nums) {

int totalSum = 0;
// 0부터 nums.length 까지 전부 합
Copy link
Contributor

Choose a reason for hiding this comment

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

저도 풀면서 알았는데 전체 합을 구하는 공식도 n*(n+1)//2 있습니다. 이 경우 순회할 필요가 없으니 더 효율적일 수 있어요.
이번주도 수고하셨습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아! ㅎㅎ 그렇군요 공유 감사해요. 댓글도 감사합니다. 연휴 잘 보내세요!

for (int i = 0; i <= nums.length; i++) {
totalSum += i;
}
// 0부터 n까지 전부 합
for (int i = 0; i < nums.length; i++) {
totalSum -= nums[i];
}

return totalSum;
}
}
29 changes: 29 additions & 0 deletions reorder-list/std-freejia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution:
def reorderList(self, head: Optional[ListNode]) -> None:
if not head or not head.next:
return
# 중간 노드 찾기
slow, fast = head, head
while fast and fast.next:
slow = slow.next # 1칸
fast = fast.next.next # 2칸

# 뒤 구간들을 뒤집는다
prev, cur = None, slow.next
# 중간노드 기준으로 앞 구간만 떼어놓는다
slow.next = None

while cur:
nxt = cur.next # 다음 노드 기억
cur.next = prev
prev = cur
cur = nxt
# 앞, 뒤 구간들을 병합
first, second = head, prev
while second:
n1, n2 = first.next, second.next
first.next = second
second.next = n1
first, second = n1, n2