2023 Huawei od machine test volume B [find the minimum number of steps] Python implementation

Table of contents

topic

        train of thought

        Code

Require


topic

Find the minimum number of steps from coordinate zero to coordinate point n. You can only move 2 or 3 to the left or right along the abscissa axis at a time. Note: The coordinate point of the path can be a negative input description. Coordinate
point
n
output describes
the output from coordinate zero The minimum number of steps to move to coordinate point n
Remark
1 <= n <= 10^9

Example 1:
Input

4
output

2
Explanation
To move from coordinate zero to 4, at least two steps are required, that is, move to the right by 2, and then move to the right by 2

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/131455344