That's a good approach as well. It looks similar to the initial approach I mentioned. However, [0] multiplied by the value of the counter would create a new list and then you are extending the list. So, the solution would not remain in-place solution. I liked capturing the ValueError approach.
Same here, I don't enjoy time challenges. Also, you can do these at your own pace. I don't do these with time. The place I feel these problems help is in understanding when to use and what to use.
Like through the initial approach I learned why index, pop would not work here, thought in the direction of in-place approach, remove, count, etc ... also have their time complexity to be O(n). So, the time complexity overall turns out to be O(n^2) likewise more similar learnings.
Extending nums doesn't really create a new list. If you check its id before and after they are still the same. Regardless, that portion of the code could be changed to:
I still have a lot to learn about big O notation myself. I'm not a professional coder so finding the time to learn takes a lot of effort. Also, not having a use/case for things makes it that much harder to stay focused on certain subjects.
Once again, I'm really impressed with all that you've been doing. It's very inspirational and motivates me to get my butt in gear!
Thank you, Martin.
That's a good approach as well. It looks similar to the initial approach I mentioned. However, [0] multiplied by the value of the counter would create a new list and then you are extending the list. So, the solution would not remain in-place solution. I liked capturing the ValueError approach.
Same here, I don't enjoy time challenges. Also, you can do these at your own pace. I don't do these with time. The place I feel these problems help is in understanding when to use and what to use.
Like through the initial approach I learned why index, pop would not work here, thought in the direction of in-place approach, remove, count, etc ... also have their time complexity to be O(n). So, the time complexity overall turns out to be O(n^2) likewise more similar learnings.
Extending nums doesn't really create a new list. If you check its
id
before and after they are still the same. Regardless, that portion of the code could be changed to:And still accomplish the same and be just as fast.
I still have a lot to learn about big O notation myself. I'm not a professional coder so finding the time to learn takes a lot of effort. Also, not having a use/case for things makes it that much harder to stay focused on certain subjects.
Once again, I'm really impressed with all that you've been doing. It's very inspirational and motivates me to get my butt in gear!
I am an absolute beginner in this time complexity thing as well. What I meant by extra memory was. When you do
[0]*count would result in [0, 0, 0]. And this list with [0, 0, 0] will have a different memory id then your nums list.
That try expect thing is really nice. I recently read about it in some blog as well. That this is a good way to do.