Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution(N) {
- const bin = N.toString(2);
- let currentGap = 0;
- let gaps = [];
- for (i=0; i<bin.length; i++){
- if (bin[i]==="0"){
- currentGap++;
- if (bin[i+1]==="1"){
- gaps.push(currentGap);
- currentGap = 0;
- }
- }
- }
- if (gaps.length===1){
- return gaps[0];
- } else if (gaps.length>1){
- return Math.max(...gaps)
- } else {
- return 0
- }
- }
- function solution(n) {
- var maxZeros = 0;
- while(n !== 0 && n % 2 === 0) {
- n >>>= 1;
- }
- for(var curr=0; n !== 0; n>>>=1) {
- if(n % 2 === 0) {
- curr++;
- } else {
- curr = 0;
- }
- maxZeros = Math.max(maxZeros, curr);
- }
- return maxZeros;
- }
- class Solution {
- public int solution(int N) {
- int count = 0;
- string binary;
- int maxLength = 0;
- char str = '0';
- binary = Convert.ToString(N, 2);
- for (int i = 0; i < binary.Length; i++)
- {
- if (binary[i] == str)
- count++;
- else
- {
- if (maxLength < count)
- maxLength = count;
- count = 0;
- }
- }
- return maxLength;
- }
- }
Add Comment
Please, Sign In to add comment