Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
True, wasn't really thinking of using a method like this in a huge program or O(n) at all.
If the array was never very long than reallocating wouldn't be all that bad.
Also, no need for 'else' statement after 'return' statement
You just turned a O(n) solution into a O(nlgn) solution :p
int max=Integer.MIN_VALUE,min=Integer.MAX_VALUE;
I believe it's better to assign them both to nums[0].
I'm not sure if it uses less memory but it's more readable and logical.
nice, you can also use Math.min() or Math.max() to fins the max or min numbers
Your right, I hadn't seen the problem from that angle. So you mean it would be better to do something like the following one :
From a theoretical standpoint, looping once for the minimum and once for the maximum is equivalent to looping once and checking for maximum and minimum at the same time (time complexity).
While this version looks nicer, you're performing a comparison of 2 values, 2 times, for each entry in the array. Additionally, you're always rewriting the value in the local variables.
Perhaps it's better to simplify to 2 ifs, and only write when relevant.
indeed you can
Thank you,
I realized my code didn't even check for multiple y's so it would have failed that test anyway.
Great. Thus, as you can see, you can much more simplify your algorithm :p
It should include a case with "yyyyaaaasss" for good measure. Currently, the single Y part does not show up in the test cases.
It was a homework assignment for an algorithms class I did a while back. I translated my answer from psudocode to java.
I don't understand why you need to iterate through all array elements so many times while you can just do something like that :
It shouldn't be your problem as the morse codes table is included in the kata, you may just use it without caring for morse codes for particular characters.
If for some strange reason you insist on using your own table, the morse code for
!
is-.-.--
.Loading more items...