| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- MySQL
- Kubernetes
- 해커랭크
- 하늘과 바람과 별과 詩
- leetcode
- hackerrank
- 파이썬
- Python
- Count Monobit Integers
- Code Jam 2022
- GitLab
- 하늘과 바람과 별과 시
- 코딩테스트
- First Unique Character in a String
- LEVEL 2
- 문제해결
- Qualification Round
- ProblemSolving
- Algorithm
- Code Jam
- 3D PRINTING
- 2022
- 알고리즘
- 프로그래머스
- swift
- ProblemSoving
- C++
- K8S
- 리트코드
Archives
- Today
- Total
공대생의 비망록
[LetCode][Easy] Two Sum II - Input Array Is Sorted 문제 Python 풀이 본문
카테고리 없음
[LetCode][Easy] Two Sum II - Input Array Is Sorted 문제 Python 풀이
myungsup1250 2026. 2. 10. 18:19투 포인터를 사용해서 푸는 대표적인 문제이다.
풀이:
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left = 0; right = len(numbers) - 1
while left < right:
temp = numbers[left] + numbers[right]
if temp == target:
return [left + 1, right + 1]
elif temp < target:
left += 1
else:
right -= 1
Comments
