8
votes
Reverse string with identical spaces as in original String using Java
You can make a String directly from a character array. So
...
4
votes
Reverse string with identical spaces as in original String using Java
I suggest you rely on StringBuilder. That way, appending to it runs in amortized constant time.
I had in mind the following implementation:
...
2
votes
Calculate square of (sum of even-indexed) - (sum of odd-indexed) subarrays from an array
This problem can be treated as a candidate for Kadane's algorithm after odd indexed elements are negated.
Original array
A = [1,2,-1,4,-1,-5]
negate odd indexed elements
B = [1,-2,-1,-4,-1,5]
Once ...
2
votes
Reverse string with identical spaces as in original String using Java
You can use IntStream.range() to get the indices of spaces.
...
2
votes
Reverse string with identical spaces as in original String using Java
I think I would do it like this:
...
2
votes
Accepted
Using methods to get and display userInput
numberEntered should not be static and should not be a member.
It's good that you made a variable for quit, but it should be ...
1
vote
Accepted
Task executor thread pool
I am assuming this is not intended for serious use, as there’s no good reason not to use the tools already provided by Java for pooling threads made available in Executors. As I am not an expert in ...
1
vote
Reverse string with identical spaces as in original String using Java
You don't need all that much to do this. Both the OP's solution and @coderodde's seem overworked with too many extraneous objects.
One StringBuilder is needed for ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
java × 10863performance × 1280
algorithm × 1275
beginner × 1017
object-oriented × 716
android × 715
programming-challenge × 637
strings × 634
array × 494
multithreading × 461
swing × 409
game × 407
interview-questions × 354
design-patterns × 304
tree × 279
sorting × 260
linked-list × 258
recursion × 216
spring × 212
unit-testing × 199
parsing × 177
concurrency × 176
homework × 174
comparative-review × 169
graph × 168