Algorithm

Home|Algorithm

AlgoExpert Notes

Easy Solution 1: HashMap put all numbers x into HashMap<Integer,Boolean> O(n) traversal array to find if y in the HashMap (y=tragetSum-x) O(n) Time complexity: O(n) Space complexity: O(n) Solution 2: Two pointers Sort the arrray. O(nLogn) use Left and Right pointer shrinking the sum to targetSum. O(n) Time complexity: O(n Log n) 

By |2022-10-10T21:44:19-04:00December 9th, 2020|Algorithm|2 Comments
Go to Top