Created
November 7, 2022 10:31
-
-
Save dluciano/bf61592e62152477656f6f3d411c6848 to your computer and use it in GitHub Desktop.
1323. Maximum 69 Number
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
public class Solution { | |
public int Maximum69Number (int num) { | |
var numBase = (int)Math.Log(num, 10); | |
var div = (int)Math.Pow(10, numBase); | |
var maxNumber = 0; | |
var flipped = false; | |
while(num > 0){ | |
var digit = num / div; | |
num = num - (digit * div); | |
if(digit == 6 && !flipped){ | |
flipped = true; | |
digit = 9; | |
} | |
maxNumber += digit * div; | |
div /= 10; | |
} | |
return maxNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment