LeetCode 1323: Maximum 69 Number Solution
Master LeetCode problem 1323 (Maximum 69 Number), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.
Problem Explanation
Explanation
To find the maximum number by changing at most one digit from 6 to 9 or from 9 to 6, we can iterate over the digits of the input number. We will replace the first occurrence of digit 6 with digit 9 to get the maximum number.
Solution Code
class Solution {
public int maximum69Number (int num) {
char[] numArray = String.valueOf(num).toCharArray();
for (int i = 0; i < numArray.length; i++) {
if (numArray[i] == '6') {
numArray[i] = '9';
break;
}
}
return Integer.parseInt(String.valueOf(numArray));
}
}Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1323 (Maximum 69 Number)?
This page provides optimized solutions for LeetCode problem 1323 (Maximum 69 Number) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.
What is the time complexity of LeetCode 1323 (Maximum 69 Number)?
The time complexity for LeetCode 1323 (Maximum 69 Number) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1323 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1323 in Java, C++, or Python.