This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complexity - O(n^2), Space Complexity - O(n^2) | |
private int[] findTriple_3(int[] A) { | |
Map<Integer, int[]> map = new HashMap<Integer, int[]>(); | |
for (int i = 0, l = A.length; i < l; i++) { | |
map.clear(); | |
for (int j = i + 1; j < l; j++) { | |
if (map.containsKey(A[j])) { | |
int[] pair = map.get(A[j]); | |
return new int[]{pair[0], pair[1], A[j]}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complexity - O(n^2), Space Complexity - O(n^2) | |
private int[] findTriple_3(int[] A) { | |
Map<Integer, int[]> map = new HashMap<Integer, int[]>(); | |
for (int i = 0, l = A.length; i < l; i++) { | |
map.clear(); | |
for (int j = i + 1; j < l; j++) { | |
if (map.containsKey(A[j])) { | |
int[] pair = map.get(A[j]); | |
return new int[]{pair[0], pair[1], A[j]}; |