I have tried to convert the original List to a 2D Array, finding that the speed of BFS is much faster than using original List.
Hope you guys know this.
(Edit: This is now obsolete, now that that was removed)
2D array just takes 335ms
That by itself is rather useless information. What's the time with nested lists?
@ManuelP The top solutions are based on nested lists. You may try their codes.
Why should every reader of your topic try those solutions when you could just tell us? Also, it wouldn't even be meaningful, since we don't know what your solution is like. Maybe it's so different from those solutions that the time difference largely comes from your different solution, not from the lists vs arrays difference. Or do you expect every reader of your topic to not only try those solutions but also modify those solutions and try them again?
First, when I said 2D array was faster than the nested list, it must base on the same algorithm, and the only difference is the data structure. And the algorithm could be various, which depends on your own idea. That's how it can make sense.
Second, why not do what you said? Some readers, like me, of course you may not, would like to try the top solutions to find out the meaning of their codes as well as the time consuming of their codes. This is a good habit to know everyone's idea and compare their ideas in practice. This topic is only for those kinds of people who are willing to try different ideas themselves, not for you. You only read and never try, so you may not suitable for this topic.
when I said 2D array was faster than the nested list, it must base on the same algorithm
Yes! Exactly! Which is why it's pointless to tell us a time that has no meaning to us because we don't know the algorithm you used. Maybe you do understand my point now? Either tell us no time at all, or tell us the times both with arrays and with lists. Telling only one of them makes no sense.
You only read and never try
Lol... as you can see, I'm trying a lot. So far 7832 submissions. And that's just with this account, which I created specifically for the purpose of trying other people's solutions (so I don't later confuse them with my own and so they don't distort my own statistics).
I do understand what your point is. The only reason I just wrote one time is that everyone has his own code, so that my time with lists may not as same as his. But the scale of time of nested list should be at the same level, which means the time consuming may not differ so much. That's why I only wrote the time with 2D arrays. So the reader can compare this time with his own time with lists.
The main reason for this topic is not to tell the reader the exact two times, I mean the final result, but let the reader know this idea so that he can try to modify his code and try himself.
Besides, I didn't see your profile before. I know you might better than me on algorithm. I just shared my idea and the reader could judge this himself.
@johnucm Ok I just tried @compton_scatter's Java solution, which works with the given lists. It took 328ms, i.e., 7ms less than yours using arrays. I guess that shows that using arrays makes things slower?
I have tried his code three times. It takes 348ms, 349ms, 342ms. Then I tried his code by just converting the list to a 2D array. Also three times. It takes 291ms, 287ms, 294ms.
I told you that the comparison must base on the same algorithm. Did you try 2D array based on his same algorithm before you replied me?
I told you that the comparison must base on the same algorithm.
Yeah and then you said "I only wrote the time with 2D arrays. So the reader can compare this time with his own time with lists". I did exactly that. (Except I used someone else's code because I don't have my own.)
Did you try 2D array based on his same algorithm before you replied me?
No, I just did what you said I should do. I'm not the one pretending it makes sense. You are. I'm just demonstrating that it doesn't.
I'm not the one pretending it makes sense. You are. I'm just demonstrating that it doesn't.
I had explained what the readers should do. If you still don't know what my point is, I won't explain this again. Also, I used your example to prove that it does make sense. If you insist it doesn't, I feel sorry for your 7k submissions.
I used your example to prove that it does make sense.
No you didn't. You used it to prove that something else makes sense. Not that it makes sense to compare our list solution's time with your array solution's time. Which is what you said, which is what I then did, and which doesn't make sense.
@ManuelP You always focus on literal sense rather than the true meaning I want to stress. I really don't know what you are struggling for?
You always focus on literal sense
Well... I can't read minds yet :-)
@ManuelP Well, then it must be very difficult for your colleagues to work with you, cause even they explain something, you are still struggling :)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.