Skip to content

Instantly share code, notes, and snippets.

@AhmetQara
Last active July 29, 2021 19:51
Show Gist options
  • Select an option

  • Save AhmetQara/da59868b472f6efcd02cc0c6e98d6131 to your computer and use it in GitHub Desktop.

Select an option

Save AhmetQara/da59868b472f6efcd02cc0c6e98d6131 to your computer and use it in GitHub Desktop.
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