Skip to content

좋다#149

Merged
github-actions[bot] merged 1 commit into
mainfrom
oliver
Apr 27, 2026
Merged

좋다#149
github-actions[bot] merged 1 commit into
mainfrom
oliver

Conversation

@snughnu
Copy link
Copy Markdown
Collaborator

@snughnu snughnu commented Apr 27, 2026

🔗 문제 링크

✔️ 소요된 시간

45m

📚 새롭게 알게된 내용

  • 투포인터 구현은 바로 떠오르네
  • two sum 문제랑 비슷해서 잘 떠오른듯

@snughnu snughnu self-assigned this Apr 27, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a two-pointer solution for the 'Good Number' problem in Swift. The feedback suggests removing a large block of commented-out code to improve maintainability and moving the 'target' variable declaration outside the while loop to optimize performance by reducing redundant array accesses.

Comment on lines +1 to +33
// 잘못된 풀이 -> 음수를 생각안함
// let n = Int(readLine()!)!
// let sortedNums = readLine()!.split(separator: " ").compactMap { Int($0) }.sorted()

// func good(_ nums: [Int], target: Int) -> Bool {
// var left = 0
// var right = nums.count - 1

// while left < right {
// let sum = nums[left] + nums[right]

// if sum < target {
// left += 1
// } else if sum > target {
// right -= 1
// } else {
// return true
// }
// }

// return false
// }

// var result = 0
// for i in 2..<n {
// let nums = Array(sortedNums[0..<i])

// if good(nums, target: sortedNums[i]) {
// result += 1
// }
// }
// print(result)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

사용하지 않는 주석 처리된 코드 블록이 대량으로 포함되어 있습니다. 코드의 가독성을 높이고 깔끔한 상태를 유지하기 위해, 불필요한 과거의 시도나 잘못된 풀이는 삭제하는 것이 좋습니다.

Comment on lines +42 to +55

while left < right {
if left == targetIndex {
left += 1
continue
}

if right == targetIndex {
right -= 1
continue
}

let sum = nums[left] + nums[right]
let target = nums[targetIndex]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

target 변수는 while 루프 내부에서 값이 변하지 않는 불변값입니다. 이를 루프 외부로 이동시키면 매 반복마다 배열 인덱스에 접근하는 연산을 줄일 수 있어 효율적입니다.

Suggested change
while left < right {
if left == targetIndex {
left += 1
continue
}
if right == targetIndex {
right -= 1
continue
}
let sum = nums[left] + nums[right]
let target = nums[targetIndex]
let target = nums[targetIndex]
while left < right {
if left == targetIndex {
left += 1
continue
}
if right == targetIndex {
right -= 1
continue
}
let sum = nums[left] + nums[right]

@github-actions github-actions Bot merged commit cd3fb8b into main Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant