1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ella [17]
4 years ago
13

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in

the binary representation of N. E.g.: The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. Write a function: class Solution { public int binary_gap(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.
Computers and Technology
1 answer:
Tems11 [23]4 years ago
6 0
This is the best way:

class Solution {    public static int solution(int N) {        return Optional.ofNullable(N)        .map(Integer::toBinaryString)        .filter(n -> n.length() > 1)        .map(t -> {            List<Integer> counts = new ArrayList<>();            int count = 0;            for(int i = 0; i < t.length(); i++)            {                if(t.charAt(i) == '0') {                    count += 1;                } else if(count > 0) {                    counts.add(count);                    count = 0;                }            }            if(counts.size() > 0) {                Collections.sort(counts);                return counts.get(counts.size() - 1);            }            return 0;        })        .orElse(0);    }}
You might be interested in
Hardware- The ______________ equipment that makes up the computer.
aleksley [76]

Answer:

It's like the stuff you can touch, the software is the stuff that runs in your computer

Explanation:

Hardware has those usb ports or whatever too (i think lol) good luck

4 0
4 years ago
I have this assignment due TONIGHT BEFORE 10PM! Please help. 50 points for whoever will help!! Here is the assignment.
saveliy_v [14]

Answer:

# include <iostream.h>

# include <conio.h>

using namespace std;

int generatelist ( int z[]);

int addlist(int x []; int y []);

int mullist(int x []; int y []);

int displayList(int z[]);

main()

{

int a[10] , b[10], add[10], mul[10];

cout<<"Enter value in array a";

generatelist(a[10]);

cout<<"Enter value in array b";

generatelist(b[10]);

for (int i=0; i<=9; i++)

{

add[i]=addlist( a[i], b[i]);

cout<<"sum of list = "<< add[i];

}

for (int i=0; i<=9; i++)

{

mul[i]=mullist( a[i], b[i]);

cout<<"multiplication of list = "<< mul[i];

}

for (int i=0; i<=9; i++)

{

displayList(a[i]);

}

for (int i=0; i<=9; i++)

{

displayList(b[i]);

}

for (int i=0; i<=9; i++)

{

displayList(add[i]);

}

for (int i=0; i<=9; i++)

{

displayList(mul[i]);

}

getch();

}

int generatelist ( int z[])

{

for (int j=0 ; j<=9 ; j++)

{

cin>>z[j];

return z[j]

}

}

int addlist(int x []; int y [])

{

int add

add=x+y;

return add;

}

int mullist(int x []; int y [])

{

int mul

mul=x*y;

return mul;

}

int displayList(int z[]);

{

for(int i=0; i<=9;i++)

cout << z[i]

}

7 0
4 years ago
The iso 14001:2004 standards require documentation of a firm's environmental program. Which component requires a plan to improve
In-s [12.5K]

The component that requires a plan to improve performance in resource use and pollutant output is the environmental management system.

<h3>What is a pollutant?</h3>

Pollutant simply means a substance that is harmful to the environment.

In this case, the component that requires a plan to improve performance in resource use and pollutant output is the environmental management system.

Learn more about pollutant on:

brainly.com/question/25537936

#SPJ12

8 0
3 years ago
JAVA
barxatty [35]

Answer:

Answer is in the provided screenshot! This was a lot of fun to make!

Explanation:

We need to create a new Array which has to be the size of amount * original - as we now that we are going to have that many elements. Then we just iterate through all the values of the new array and set them equal to each of the elements in order.

Ignore the code in my main function, this was to print to the terminal the working code - as you can see from the output at the bottom!

5 0
3 years ago
Where can we buy a cryptocurrency? from below options
dem82 [27]

it would be C

hope this helps!

8 0
3 years ago
Other questions:
  • ____ are types of changes that occur when text has been omitted from a document and must be inserted later.
    10·1 answer
  • Clifford visits a website that has a lot of multimedia content. He watches a few videos. However, some videos do not play. The b
    14·1 answer
  • Osha requires employers pay for most required personal protective equipment including
    11·1 answer
  • What are three responsibilities of an operating system? please answer quick!!!
    9·1 answer
  • Which is the best practice for placing graphics on a slide?
    6·2 answers
  • In a stream channel what is deposited first?
    7·1 answer
  • How does the author of let bindi have the limelight persuade readers to consider the importance of wildlife conservation
    9·2 answers
  • The purpose of the ________ in a database system is to receive requests from applications and to translate those requests into r
    12·1 answer
  • Answer for 3 and 4 please
    15·2 answers
  • Write C# program that will read name from keyboard and display it on screen. The program should throw an exception when the leng
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!