Leetcode Move Zero

Source: Internet
Author: User

Tags: idea assignment array access access. com pointer amp is a direct

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.


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

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

Leetcode Move Zero

Related Article

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.

Tags Index: