Leetcode 755 Solution
This article provides solution to leetcode question 755 (reach-a-number)
Access this page by simply typing in "lcs 755" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/reach-a-number
Solution
class Solution {
public:
int reachNumber(int target) {
target = abs(target);
int k = 0;
while (target > 0)
target -= ++k;
return target % 2 ? k + 1 + k % 2 : k;
}
};