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.
guys ours looks the best 😎
I understand, thank you for the explanation!
Is there any difference between importing the library first opposed to doing Math.abs() ?
It is not best practice. The same people that go on leetcode that demands more of them and then downvote the problem come here to do their shenanigans and upvote the clever answers and call them a best practice. Bunch of 12 year olds.
This can be changed by making a copy of the input parameter and working on that.
The problem with the iterator is that you would need a cyclic iterator, or starting iterating over and over again.
The reason why you should not remove or add an element from a collection while iterating it is the iterating method might throw a Concurrent exception. But the code here only calls for List.size() which is ok.
Removeing items from a list with 'items.remove((int) position)' is bad in two ways:
What do you think about an iterator on a LinkedList?
I'm curious: How can this work?
Isn't removing items from a list forbidden while you are traversing it?
A ConcurrentModificationException should be thrown, and therefore, you would need to use iterators to be able to remove elements from the list you are traversing.
In this particular case it doesn't make sense.
Probably author had to cast while developing the solution and then forgot to remove it during final refactoring.
Could someone please explain the purpose of casting position as an int when adding the element to permutation? Isn't position already an int?
Thanks
This comment is hidden because it contains spoiler information about the solution
I agree. it's not best practise, but it is clever :)
The tests internally use
float
s instead ofdouble
s which can lead to failing random tests.It's easy to fix, see the issue by @kayakero
I don't think it's the best practice. It's less code, however, it's much more resource consuming than a simple condition.
So it seems, but feel free to check yourself or to reply directly, in case you deem it useful.
And thanks for your time again :)
Loading more items...