Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
給定一個整數數列nums 和一個整數 target
返回兩個數字,這兩個數加起來就等於target
You may assume that each input would have exactly one solution and each number can only be used once.
您可以假設每個輸入只有一個解決方案,並且每個數字只能使用一次
You should return the answer in ascending order.
請使用 升序 輸出答案
There are two parts in one input line:
The input is well parsed in two variable: target and nums in the given template code
nums[i] is integer < 30000 for all i in range(size(num))
Two integers represent the index from the list (location of list start from 0)
If you use list or numpy array, you can directly print the list or numpy array
9 2 7 11 15
0 1
20 9 10 5 15
2 3
Brute force:
simply go through twice loops to find a pair which sum to target, the "time complexity" is O(N^2)
Can you think out some method to accelerate the program to reduce the time complexity to O(NlogN) or even O(N)? (such as "sort","hashing"or "set")
ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |