LeetCode, leetcodeoj
At the beginning, if you want to update the DP step by step, find the minimum number of steps to jump to the last step, but the time complexity O (nk) Will time out.
After thinking about this question, you only need to return whether the question can reach the last one without the minimum number of steps. Therefore, during iteration, you only need to retain the currently reachable tmpMax, the time complexity is reduced to O (n ).
Class Solution {public: const int MAXVALUE = 1 <30; bool canJump (int A [], int n) {int tmpMax = 0; if (n = 1) return true; for (int I = 0; I <n-1; I ++) {if (I> tmpMax) return false; if (tmpMax <I + A [I]) tmpMax = I + A [I]; if (tmpMax> = n-1) return true;} return false ;}};
What is leetcode?
There are many programming and interview questions, which can be compiled and run online. It is difficult. If you can do it all by yourself, it is very helpful for large companies. I just did the questions there.
C ++ leetcode always says that the compilation is wrong. The key is that I don't even have 77th lines, only those lines ......
Neither leetcode can define the main function.
You need to construct a Solution class
The main of the 77 rows of redefine happens to be the main function of leetcode used to test the Solution you write.