Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 493 Bytes

1323.Maximum69Number.md

File metadata and controls

22 lines (19 loc) · 493 Bytes

1323. Maximum 69 Number

Easy

Given a positive integer num consisting only of digits 6 and 9.

Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).

class Solution {
public:
    int maximum69Number (int num) {
        string n = to_string(num);
        for(int i = 0; i < n.length(); i++){
            if(n[i] == '6'){
                n[i] = '9';
                break;
            }   
        }
        return stoi(n);
    }
};