Last active
July 29, 2021 19:51
-
-
Save AhmetQara/da59868b472f6efcd02cc0c6e98d6131 to your computer and use it in GitHub Desktop.
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
| class Solution { | |
| int[] myArr; | |
| public static int[] add(int n, int arr[], int x) | |
| { | |
| int i; | |
| int newarr[] = new int[n + 1]; | |
| for (i = 0; i < n; i++) | |
| newarr[i] = arr[i]; | |
| newarr[n] = x; | |
| return newarr; | |
| } | |
| 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 & i != j ) { | |
| myArr = add(0,myArr,i); | |
| myArr = add(1,myArr,j); | |
| } | |
| } | |
| } | |
| return myArr; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment