| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
| 29 | 30 | 31 |
Tags
- Algorithm
- C++
- 3D PRINTING
- hackerrank
- swift
- Qualification Round
- Kubernetes
- First Unique Character in a String
- Code Jam
- Python
- Count Monobit Integers
- 프로그래머스
- 하늘과 바람과 별과 詩
- 파이썬
- leetcode
- GitLab
- ProblemSolving
- 문제해결
- 코딩테스트
- 리트코드
- MySQL
- K8S
- LEVEL 2
- 2022
- ProblemSoving
- 알고리즘
- 해커랭크
- 하늘과 바람과 별과 시
- Code Jam 2022
Archives
- Today
- Total
공대생의 비망록
[LeetCode][Easy] Two Sum II - Input Array Is Sorted 문제 Python 풀이 본문
Programming Language/Python
[LeetCode][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'Programming Language > Python' 카테고리의 다른 글
| [LeetCode][Easy] Valid Parentheses 문제 Python 풀이 (0) | 2026.02.10 |
|---|---|
| [LeetCode][Easy] Longest Common Prefix 문제 Python 풀이 (0) | 2026.02.09 |
| [LeetCode][Easy] Valid Palindrome 문제 Python 풀이 (0) | 2026.02.09 |
| [LeetCode][Easy] First Unique Character in a String 문제 Python 풀이 (0) | 2026.02.09 |
| [LeetCode][Easy] Valid Anagram 문제 Python 풀이 (0) | 2026.02.08 |
Comments