LeetCode 1323. Maximum 69 Number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
static auto x = []()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    return 0;
}();
class Solution {
public:
    int maximum69Number (int num) {
        stack<int> s;
        int now=num;
        while(now!=0){
            s.push(now%10);
            now/=10;
        }
       
        bool changed=false;
        int ret=0;
        while(!s.empty()){
            if(changed){
                ret=ret*10+s.top();
                s.pop();
            }
            else{
                if(s.top()==6){
                    changed=true;
                }
                ret=ret*10+9;
                s.pop();
            }
        }
        return ret;
    }
};



4 Replies to “LeetCode 1323. Maximum 69 Number”

  1. May I simply just say what a comfort to discover somebody who truly knows what they are talking about online.
    You definitely understand how to bring a problem to light and make it important.
    More people have to read this and understand this side of
    your story. It’s surprising you aren’t more popular given that you definitely have the gift.

Leave a Reply

Your email address will not be published. Required fields are marked *