LeetCode, leetcodeoj

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.