Guest User

Untitled

a guest
Apr 24th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int findComplement(int num) {
  4. string s = "";
  5. int ind = 0;
  6. while(num>0){
  7. if(num%2==0)
  8. s+='1';
  9. else
  10. s+='0';
  11. ind++;
  12. num/=2;
  13. }
  14. int ans=0;
  15. int mul=1;
  16. for(int i=0;i<s.length();i++){
  17. ans += (s[i]-'0')*mul;
  18. mul*=2;
  19. }
  20.  
  21. return ans;
  22. }
  23. };
Add Comment
Please, Sign In to add comment