Skip to content

Commit

Permalink
2024-04-18 20:30:22
Browse files Browse the repository at this point in the history
Affected files:
src/content/blog/boj-2230-수-고르기.md
  • Loading branch information
gyunseo committed Apr 18, 2024
1 parent 3fe85bf commit 443e2b2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/content/blog/boj-2230-수-고르기.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,37 @@ if __name__ == "__main__":
print(minAns)

```

## Two Pointers를 이용한 방법

```python
import sys
from bisect import bisect_left

input = sys.stdin.readline
MAX = 2 * int(1e9) + 1
minAns = MAX


def OOB(j):
if j < 0 or j >= N:
return True
return False


if __name__ == "__main__":
N, M = map(int, input().rstrip().split())
A = sorted([int(input().rstrip()) for _ in range(N)])
e = 0
for s in range(len(A)):
while not OOB(e) and A[e] - A[s] < M:
e += 1
if e == len(A):
break
minAns = min(minAns, A[e] - A[s])

print(minAns)
```

인덱스 하나 차이로 런타임 오류나 WA를 판정 받을 수 있다.
꼼꼼히 OOB 함수등을 이용해서, 인덱스 체크를 하자.

0 comments on commit 443e2b2

Please sign in to comment.