Genius ask the Java problem question in Typescript relate server
I currently learning JAVA, so i rewriting my old JS algorithm from leetcode to practice JAVA.
the problem is this code right below make "Time Limit Exceeded" error.
but when you use same code but update else if else instead of just if guards it works fine.
i really can not understand why, because i tried to add "continue" at the end of every if statement and the same error occur when is should skip in that logic cicle.
Thanks in advance
4 Replies
Probably some compiler optimization is being lost when you do the separate three ifs versus the one control flow
That’s why you see that issue
And just to add to the discussion if -> continue will almost certainly result in more bytecode (and worse perf) than if -> else if since the JVM will have to find what is needing to be continued since it hypothetically could be inside nested loops
thanks guys @keef (Rustular CVO) @Vincent
I thought at first maybe i am doing something really wrong. Also i really like Java, when i created C# backend i was really regretting it. But Java is cool.
Yeah I was guessing this too. nice to see it was the right idea