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



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |