Skip to content

Instantly share code, notes, and snippets.

@wahyuoi
Created May 7, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wahyuoi/9663b06cbdba7d908ee5ce99e80485a8 to your computer and use it in GitHub Desktop.
Save wahyuoi/9663b06cbdba7d908ee5ce99e80485a8 to your computer and use it in GitHub Desktop.
public class Solution {
public int missingNumber(int[] nums) {
for (int num : nums) {
jump(num, nums);
}
for (int i = 0; i < nums.length; i++) {
if (nums[i] != -1) return i;
}
return nums.length;
}
private void jump(int num, int[] nums) {
if (num == -1) return;
if (num == nums.length) return;
int temp = nums[num];
nums[num] = -1;
jump(temp, nums);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment