Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * brute force
- * T(n) = O(n^2)
- * S(n) = O(1);
- * @param nums
- * @param target
- * @return
- */
- public int[] twoSum(int[] nums, int target) {
- for (int i = 0; i<nums.length; i++) {
- for (int j=0; j<nums.length; j++) {
- if (nums[i] + nums[j] == target) {
- return new int[] {i,j};
- }
- }
- }
- throw new IllegalArgumentException("nums should have one solution");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement