Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created February 12, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/c4b613504108f095f368c875dbadeda7 to your computer and use it in GitHub Desktop.
Save fpdjsns/c4b613504108f095f368c875dbadeda7 to your computer and use it in GitHub Desktop.
[leetcode] 991. Broken Calculator : https://leetcode.com/problems/broken-calculator/
class Solution {
public:
int brokenCalc(int X, int Y) {
if(X==Y) return 0;
if(X > Y) return X-Y;
if(X < Y && Y%2 == 0){
return 1 + brokenCalc(X, Y/2);
}
return 1 + brokenCalc(X, Y+1);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment