From 67c261a92088b32d557f69b451b67612f54de462 Mon Sep 17 00:00:00 2001 From: Kevin Naughton Jr Date: Tue, 5 Jun 2018 14:17:29 -0400 Subject: [PATCH] added PowerOfTwo.java --- .DS_Store | Bin 6148 -> 6148 bytes company/.DS_Store | Bin 18436 -> 8196 bytes company/google/PowerOfTwo.java | 25 ++++++++++++++++++++++ leetcode/.DS_Store | Bin 8196 -> 8196 bytes leetcode/bit-manipulation/PowerOfTwo.java | 25 ++++++++++++++++++++++ leetcode/math/PowerOfTwo.java | 25 ++++++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 company/google/PowerOfTwo.java create mode 100644 leetcode/bit-manipulation/PowerOfTwo.java create mode 100644 leetcode/math/PowerOfTwo.java diff --git a/.DS_Store b/.DS_Store index 034b6c289592204254b50521b70ebc64582b9780..74bb090087b11d8af99cd0b2e6b5dc31947cba34 100644 GIT binary patch delta 156 zcmZoMXfc=|#>B!ku~2NHo}wrV0|Nsi1A_nqLn1>SLuFEVaY0hf=0N7<%)%fkc7|kz ze1=?x0*Lfv1*V-G#>S>P3dSZDlOHmB)qu~2NHo}wrd0|Nsi1A_nqLo!1?LkdG`Qh9N~#=_-{lMO^zCcChn z;xIKb(@`)oGoE~(#eH)u+bYJ54W`VS**W+*fTnB~Vuux=VYR{OwUQ(QkQ`x})WETU&YS%Kp zpS)UInHOjVLp~6ugRGx?Ut67t#|w*T^L5y9n|5Efp7HABcs(@JHk--DF$yw6ESBH~ n(yk!?Z!G-IJel7mkOSyzP^d6Wj^~*=S;6oyPS@f#KbjE$DYaKv literal 18436 zcmeHOYiu0V6+XxDV+K#-@gpJG*z)EzyV;#xw5D z+NMd}y5$E@3W&ah%0r|;X?Y{@YLWOsTT~TQY9T;V@lv6c_yba@3P@GebMKwm%+A`X zTRUW(%&cb4+}AwLe&>Goo_huWuyrD_1t1Cl675W?3P4jaK$v7bNq1xAY|q-3Q4Z1` zqCKD516Xhv4A2aFvNx-CkP&Dg&_JMpKm&mW0uAJX1{in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{E2l0yUYc9wTNL}(9GH@MNxsU$|&ffjn&m^9-&^8U2~45fHRpO4JW>*NgSTA9nUN&o0GaE5rCA&W99{oK7G_=)JK z(|qrraDM9ahH2yWctz$IpOROkd&N>2pEBRxdFT~cFj~)&dt_eY(~N%CM^qAY5>1Vg zgCtH=Wx>&atN@ssBug;?VV&FF`{<1`yzgI-8znahYc?$Z7pF=>oxSdRnEFA zf5C{&Wzx#RtdF<~p^Fn14<`>uOOO`tz!v$y!e=s+9gKKseR;{R14h5arZQ}ez+J57 zNuD#WRqI^tJTma=>o~GvS%S{P9r5~td^{uG>*sLMw6?XDx99NEi{C|aUM>)xHf-0_ z=O35yIj#$e$4q-(I^D+>65lwJQ4zuXf0p^b2;OC3w6l!?+)%c_dwULsvMqRYa8_d4 z=HcIbz!=%Am6(mscZ#D1-ky0P`#b7YJfY6P|ym;kCsI5EA$C4)p{6 z_eDhp{68!I7YgV^SqwnO+~5DZ01ITGfj|T2paw9%y|2BMUd;Vm!2gbHk`ShSgm$*E zdNV@uCUjs`SU&$8j}q*2ylyA2*O4PkvW@D^2+5mMnl~rOo0DYCSv~PJ-=cpENU`l_ bJh+g*0R;T-#0C4*5zPPR@p;6VT>t+ML#IsI diff --git a/company/google/PowerOfTwo.java b/company/google/PowerOfTwo.java new file mode 100644 index 0000000..793a00a --- /dev/null +++ b/company/google/PowerOfTwo.java @@ -0,0 +1,25 @@ +//Given an integer, write a function to determine if it is a power of two. +// +//Example 1: +// +//Input: 1 +//Output: true +//Example 2: +// +//Input: 16 +//Output: true +//Example 3: +// +//Input: 218 +//Output: false + +class PowerOfTwo { + public boolean isPowerOfTwo(int n) { + long i = 1; + while(i < n) { + i <<= 1; + } + + return i == n; + } +} diff --git a/leetcode/.DS_Store b/leetcode/.DS_Store index f6bd90eb7c699930ff0ae143772390229979652a..137d8412146d4dcd79c1a4d2d56180b882e6cb0d 100644 GIT binary patch delta 106 zcmZp1XmOa}&&akhU^hP_+h!htC2X8547m)63?&R1lcfZ9au^$%>L?hSSWLbx;Ep7< PP|S8SyTnSORa*f7s-_yW delta 40 rcmZp1XmOa}&&aYdU^hP_%Vr*dC2W&#itBA`&}7`qF0m5IQDX!E5he{x diff --git a/leetcode/bit-manipulation/PowerOfTwo.java b/leetcode/bit-manipulation/PowerOfTwo.java new file mode 100644 index 0000000..793a00a --- /dev/null +++ b/leetcode/bit-manipulation/PowerOfTwo.java @@ -0,0 +1,25 @@ +//Given an integer, write a function to determine if it is a power of two. +// +//Example 1: +// +//Input: 1 +//Output: true +//Example 2: +// +//Input: 16 +//Output: true +//Example 3: +// +//Input: 218 +//Output: false + +class PowerOfTwo { + public boolean isPowerOfTwo(int n) { + long i = 1; + while(i < n) { + i <<= 1; + } + + return i == n; + } +} diff --git a/leetcode/math/PowerOfTwo.java b/leetcode/math/PowerOfTwo.java new file mode 100644 index 0000000..793a00a --- /dev/null +++ b/leetcode/math/PowerOfTwo.java @@ -0,0 +1,25 @@ +//Given an integer, write a function to determine if it is a power of two. +// +//Example 1: +// +//Input: 1 +//Output: true +//Example 2: +// +//Input: 16 +//Output: true +//Example 3: +// +//Input: 218 +//Output: false + +class PowerOfTwo { + public boolean isPowerOfTwo(int n) { + long i = 1; + while(i < n) { + i <<= 1; + } + + return i == n; + } +}