Leetcode Move Zero

Source: Internet
Author: User

Own ideas:

/* First Appearance 0 */

/* Record the number of consecutive 0 N */

/* Second occurrence 0 record position */

/* Move all elements before the second 0 to the left n*/

/* Return to step two */

/* Finally assign all remaining positions to the 0*/

Problems encountered in the implementation:

1, array access out of bounds,&& operator order, first cannot cross

2, record the number of 0, carefully consider the position

On-Line ideas:

This type of array in-situ delete the data, the study is two pointer application, pay attention to grasp the idea of two pointers, this kind of problem can be solved.

Conclusion:

Suddenly, the array elements can be directly assigned to the double pointer problem.

Reference: HTTPS://WWW.JIANSHU.COM/P/05338B2180A1

Leetcode Move Zero

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.