Power of Two | LeetCode 231 | C++, Java, Python

preview_player
Показать описание

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

June LeetCoding Challenge | Problem 8 | Power of Two | 8 June,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Power of Two,
Power of Two c++,
Power of Two Java,
Power of Two python,
Power of Two solution,
231. Power of Two,

#Facebook #CodingInterview #LeetCode #JuneLeetCodingChallenge #Google #Amazon #PowerOfTwo
Рекомендации по теме
Комментарии
Автор

Another good explanation from Knowledge Center :D

md.tarekhasan
Автор

Bhai constraint is you should be given negative numbers too ?? How you tackle -ve numbers??

cognizant
Автор

sir, how can i know that my submitted answer is best?? i mean i don't understand how to check my recent submission is better than previous one?

mayankgupta
Автор

How do you tackle the case where the numbers are fractions like 1/2, 1/4, 1/8....and I do understand that the given number is integer so yes it would work for the given problem ...but I'm asking you in general .I solved it using log2 function which would even work for the cases of fractions

giri_teja
Автор

Have solved it already. ;P
class Solution {
public boolean isPowerOfTwo(int n) {
return n>0 && (n&(n-1))==0 ? true : false;
}
}

md.tarekhasan
visit shbcf.ru