Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- static int ariphmeticSequence(int n) {
- int result = 0;
- int prev = 0;
- while (prev < n) {
- result += prev + 1;
- prev += 1;
- }
- return result;
- }
- public int missingNumber(int[] nums) {
- int temp_summ = 0;
- boolean ifZero = false;
- for(int i: nums) {
- if (i == 0) ifZero = true;
- temp_summ += i;
- }
- if (ariphmeticSequence(nums.length) == temp_summ) {
- if (!ifZero) return 0;
- return nums.length + 1;
- } else {
- return ariphmeticSequence(nums.length) - temp_summ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement