Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

std::vector< bool >##>

#LIVE DEMO #

LIVE DEMO

std::vector< bool >##

#LIVE DEMO #

std::vector< bool >

LIVE DEMO

added 176 characters in body
Source Link

EDIT

Change the last line in findLargestGap() from it++ to it = next_true to start the next iteration where the last one was found to save cycles in some cases.

#LIVE DEMO LIVE DEMO#

EDIT

Change the last line in findLargestGap() from it++ to it = next_true to start the next iteration where the last one was found to save cycles in some cases.

#LIVE DEMO#

added 969 characters in body
Source Link

Your question states that you want to solve this problem in C++/C++14. In your solution you are mainly using old C style code.

In order to make your code more readable / maintable / bug-free (you choose!), try to make use of STL as much as possible.

std::vector< bool >##

Using std::vector<bool> as the binary representation we can make use of the algorithm library of STL.

STL iterators

When dealing with containers in STL, iterator s are used to specify a range for a container. These begin and end iterators (specifying a range) are needed for the algorithms.

STL algorithm

The STL algorithm module has most of algorithms you need for manipulating containers. Try to use STL algorithms as much as possible whenever you need to operate on a range of elements.

Here is another approach using std::vector<bool>, iterators and algorithm from STL.

LIVE DEMO #LIVE DEMO #

Here is another approach using std::vector<bool>, iterators and algorithm from STL.

LIVE DEMO

Your question states that you want to solve this problem in C++/C++14. In your solution you are mainly using old C style code.

In order to make your code more readable / maintable / bug-free (you choose!), try to make use of STL as much as possible.

std::vector< bool >##

Using std::vector<bool> as the binary representation we can make use of the algorithm library of STL.

STL iterators

When dealing with containers in STL, iterator s are used to specify a range for a container. These begin and end iterators (specifying a range) are needed for the algorithms.

STL algorithm

The STL algorithm module has most of algorithms you need for manipulating containers. Try to use STL algorithms as much as possible whenever you need to operate on a range of elements.

Here is another approach using std::vector<bool>, iterators and algorithm from STL.

#LIVE DEMO #

Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /