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
Give an example of a process that may need a flowchart to clarify procedures.<br><br> HELP ASAP!
11111nata11111 [884]

To understand flow of programming logic flow chat technique been used. Once end user starts any learning programming flow chat design been learned and corrected the mistake. After success of flow chat design end user been advice to do programming and tested in computer.

<u>Explanation:</u>

In flow chart design is used for beginner level programming. Some time to make higher level managers to understand this flow chart design is used.

Flow chart has start, procedure, condition, function or procedure and end with stop diagrams.

Flow chart makes end user understand the flow of logics.

Suppose we need to do a process for a procedure, end user has to design with start flow chart symbol and put a procedure flow chart symbol with identification character, then end user has use same identification character and start designing the procedure in the flow chart diagram.

Procedure in flow char design is used to call same procedure number of time, so that repeated coding is avoided.

5 0
3 years ago
Many of today’s digital devices operate on battery power supplied by what kind of ion batteries.
stich3 [128]
"Lithium ion" is used in your cellphone.
6 0
3 years ago
The WAN connections to your regional offices are unfortunately extremely slow for your users and they are complaining about file
Zanzabum

Answer: (B) Branch cache

Explanation:

  The branch cache is the process of cache the data from the given file and the wen server on the wide area network. In the WAN connection, the branch code is the type of functionality which basically allow the window to providing the remote user support in the network. The branch cache basically work on the two mode that are:

  • The distributed mode
  • The host mode

The branch cache is the one of the technology that intend the cache data for reducing the network traffic in the wide are network.

Therefore, Option (B) is correct.

5 0
3 years ago
The process of capturing moving images on film or a digital storage device is called?
galben [10]

Answer:

Cinematography

Explanation:

Cinematography is the blend of art and science and it deals with the recording of moving images on film or a digital storage device.

While making a movie some example of cinematography are the conclusions reached about lighting, camera filters, lenses etc.

6 0
3 years ago
Which feature is used to help identify the appropriate content for particular form fields?
Alika [10]

Answer:

The correct option is;

Content controls

Explanation:

Content controls are customizable controls that can be added to forms, templates and document that enable users to identify or preview the expected data that fills a given form field

Content controls can be in the form of instructional text that give users an idea of the expected format of the content of a given form field, such that the text disappears as soon as the user starts typing in their own text.

6 0
3 years ago
Other questions:
  • What are the top and side margins for a letter typed in standard format?
    11·1 answer
  • . How to insert Section Break in Microsoft word 2016 ?
    14·1 answer
  • Suppose Host A sends Host B a TCP segment encapsulated in an IP datagram. When Host B receives the datagram, how does the networ
    11·1 answer
  • Most airlines use very modern hardware and software.<br><br><br> True<br><br> False
    9·1 answer
  • Binary search takes a list of information and divides the list into two parts, one is divided and one is kept.
    15·1 answer
  • Because all the IEEE WLAN features are isolated in the PHY and ____________ layers, practically any LAN application will run on
    11·1 answer
  • At Greenwood ATCT, arrival information need NOT be forwarded while FDIO is operational unless the sequence of aircraft changes a
    6·1 answer
  • How is an operating system like a translator?
    12·1 answer
  • Make and run a Python program which:
    13·1 answer
  • rue or false: The first web browser was introduced to the public in the 1970s and started the explosive growth of the Internet i
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!