Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findint(input) {
  2.     let bits = (1 << input.length) - 1;
  3.    
  4.     console.log('s:', (bits).toString(2));
  5.  
  6.     for(let i=0; i<input.length; i++) {
  7.         let curr = input[i];
  8.        
  9.         if(curr <= input.length && curr > 0) {
  10.             bits = bits ^ (1 << (curr-1))
  11.         }
  12.        
  13.         console.log((bits).toString(2));
  14.     }
  15.  
  16.     bits &= -bits;
  17.     console.log('e:', (bits).toString(2));
  18.     return Math.log2(bits) + 1;
  19. }
  20.  
  21. // len = 5 : 1 2 3 4 5
  22.  
  23. console.log(findint([1, 2, 0])) // 3
  24. console.log(findint([3, 4, -1, 1])) // 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement