[LeetCode][Python3] 1. Two Sum
2018. 9. 10. 23:04 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/two-sum/description/
My Solution :
class Solution:
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
cache = {}
for i, num in enumerate(nums):
if target - num in cache:
return [cache[target-num], i]
cache[num] = i
Comment :
HackerRank는 Easy 문제를 거의 다 풀어본 듯 하니, 오늘부터 LeetCode Easy 문제를 풀어볼 생각이다.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 27. Remove Element (0) | 2018.09.11 |
---|---|
[LeetCode][Python3] 26. Remove Duplicates from Sorted Array (0) | 2018.09.11 |
[LeetCode][Python3] 7. Reverse Integer (0) | 2018.09.11 |
[LeetCode][Python3] 21. Merge Two Sorted Lists (0) | 2018.09.11 |
[LeetCode][Python3] 20. Valid Parentheses (0) | 2018.09.11 |
[LeetCode][Python3] 14. Longest Common Prefix (0) | 2018.09.11 |
[LeetCode][Python3] 13. Roman to Integer (0) | 2018.09.11 |
[LeetCode][Python3] 9. Palindrome Number (0) | 2018.09.10 |
최근에 달린 댓글 최근에 달린 댓글