Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 파이썬
- github
- 백준
- SW Expert Academy
- 더현대서울 맛집
- Baekjoon
- 데이콘
- hackerrank
- dacon
- Kaggle
- AI 경진대회
- programmers
- ChatGPT
- 편스토랑
- 프로그래머스
- PYTHON
- 맥북
- Docker
- 프로그래머스 파이썬
- gs25
- 금융문자분석경진대회
- 자연어처리
- 코로나19
- ubuntu
- Git
- 우분투
- Real or Not? NLP with Disaster Tweets
- leetcode
- 캐치카페
- 편스토랑 우승상품
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1. Two Sum (Python) 본문
728x90
반응형
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
Solution
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for index, num in enumerate(nums):
if (target - num in nums) and (index != nums.index(target-num)):
return index, nums.index(target-num)
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 372. Super Pow (Python) (0) | 2020.07.15 |
---|---|
[leetCode] 371. Sum of Two Integers (Python) (0) | 2020.07.14 |
[leetCode] 231. Power of Two (Python) (0) | 2020.07.12 |
[leetCode] 989. Add to Array-Form of Integer (Python) (0) | 2020.07.11 |
[HackerRank] Day 14: Scope (Python) (0) | 2020.07.10 |
Comments