-
91. Two Sum II - Input Array Is SortedProblem Solving 2023. 1. 19. 04:31728x90
https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/
Two Sum II - Input Array Is Sorted - LeetCode
Two Sum II - Input Array Is Sorted - Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2
leetcode.com
더해서 target과 같은 값을 만드는 두 개의 수가 각각 몇 번째에 위치해 있는지 출력하는 문제
class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: for i, a in enumerate(numbers): if i > 0 and a == numbers[i - 1]: continue for j, b in enumerate(numbers[i+1:]): if a + b > target: break elif a + b == target: print(a, b) return [i+1] + [i + j + 1 + 1]
시간초과의 늪에 걸려서 장치 두 개를 추가했다...
'Problem Solving' 카테고리의 다른 글
93. 크로아티아 알파벳 (1) 2023.01.19 92. Number of 1 Bits (0) 2023.01.19 90. Valid Parentheses (0) 2023.01.19 89. Unique Morse Code Words (0) 2023.01.19 88. 욱제는 효도쟁이야!! (0) 2023.01.19