Skip to content

Commit 269d4d7

Browse files
authored
Create Longest_consecutive_1's.cpp
1 parent d4e875e commit 269d4d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Bits/Longest_consecutive_1's.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution
2+
{
3+
public:
4+
int maxConsecutiveOnes(int N)
5+
{
6+
int count=0;
7+
while(N!=0)
8+
{
9+
N=(N & (N<<1));
10+
11+
count++;
12+
}
13+
14+
return count;
15+
}
16+
};

0 commit comments

Comments
 (0)