754. 到达终点数字

754. 到达终点数字

class Solution {
    public int reachNumber(int target) {
        target = Math.abs(target);
        int n = 0, sum = 0;
        while(sum < target || (sum - target) % 2 == 1) {
            n++;
            sum += n;
        }
        return n;
    }
}   
posted @ 2022-11-04 21:54  Eiffelzero  阅读(24)  评论(0)    收藏  举报