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.
Similar code, nice
Also, looking up if an element is in a set happens in a constant time, i. e., it always takes the same amount of time, regardless of the size of the set. Looking up if an element is in a list happens in a linear time, i. e. in the worst case, it has to go over all the elements of the list, and here, it would be very inefficient since we have to search the data structures repeatedly.
Hey, can anyone tell me how this can be useful in real life example? I can understand what happened here, but it looks more complicated than the other solutions. Is it a method that has more practicle use in real life projects?
Hope I wasn't being rude.
This looks more efficient than the top rated one on the list, but there can be some improvements. By adding
text = text.lower()
you won't repeatedly call the lower() function, which helps with efficiency. Also, you can use a dictionary rather than two sets. I'm not a pro at python or even close to it, but I'm making an effor to review solutions to see how I could change it to make improvements. I even came to the dictionary conclusion by asking chatgpt (facepalm), so I refuse to take any credit! Nice solution regardless :).Nice and clean solution.
Smart optimisation!
great!
cause the element in set() is single, and it will delete the repeated
This comment is hidden because it contains spoiler information about the solution
My solution was almost identical. If you place "seen.add(char)" inside an else then speed will be slighly improved.
If you have a one million characters text then after a few iterations 99.99% of the characters will be already in 'seen' set so that line of code could be skipped most of the time.
Can't be changed
And increases efficiency
This comment is hidden because it contains spoiler information about the solution
for how much cleaner it is, it's only marginially slower than my solution; Only once we get to a test size of 2,500,000 data points does my solution actually start to be "noticiably faster" (180ms vs 320ms)
but how fast ...
Loading more items...