Created
February 12, 2019 16:34
-
-
Save fpdjsns/c4b613504108f095f368c875dbadeda7 to your computer and use it in GitHub Desktop.
[leetcode] 991. Broken Calculator : https://leetcode.com/problems/broken-calculator/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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