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
- SW Expert Academy
- 편스토랑
- 더현대서울 맛집
- 캐치카페
- 자연어처리
- gs25
- leetcode
- Kaggle
- 데이콘
- 편스토랑 우승상품
- 백준
- PYTHON
- ubuntu
- ChatGPT
- hackerrank
- Docker
- 우분투
- dacon
- AI 경진대회
- Git
- github
- 파이썬
- Real or Not? NLP with Disaster Tweets
- 맥북
- 금융문자분석경진대회
- 코로나19
- 프로그래머스
- Baekjoon
- 프로그래머스 파이썬
- programmers
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