MCPcopy Create free account
hub / github.com/crossoverJie/JCSprout / getTwo1

Method getTwo1

src/main/java/com/crossoverjie/algorithm/TwoSum.java:21–35  ·  view source on GitHub ↗

时间复杂度为 O(N^2) @param nums @param target @return

(int[] nums,int target)

Source from the content-addressed store, hash-verified

19 * @return
20 */
21 public int[] getTwo1(int[] nums,int target){
22 int[] result = null;
23
24 for (int i= 0 ;i<nums.length ;i++){
25 int a = nums[i] ;
26 for (int j = nums.length -1 ;j >=0 ;j--){
27 int b = nums[j] ;
28
29 if (i != j && (a + b) == target) {
30 result = new int[]{i,j} ;
31 }
32 }
33 }
34 return result ;
35 }
36
37
38 /**

Callers 1

getTwo1Method · 0.95

Calls

no outgoing calls

Tested by 1

getTwo1Method · 0.76