0754. Reach a Number
https://leetcode.com/problems/reach-a-number
Description
You are standing at position 0
on an infinite number line. There is a destination at position target
.
You can make some number of moves numMoves
so that:
On each move, you can either go left or right.
During the
ith
move (starting fromi == 1
toi == numMoves
), you takei
steps in the chosen direction.
Given the integer target
, return the minimum number of moves required (i.e., the minimum numMoves
) to reach the destination.
Example 1:
Example 2:
Constraints:
-109 <= target <= 109
target != 0
ac
Last updated