Maximum 69 Number LeetCode solution in C++

1
class Solution {
2
public:
3
int maximum69Number(int num) {
4
string s = to_string(num);
5

6
/* You can change at the most one digit,
7
so traverse from left and change the first
8
encountered 6 to 9 (to increase th value of num) */
9

10
for (int i = 0; i < s.size(); i++) {
11
if (s[i] == '6') {
12
s[i] = '9';
13
break;
14
}
15
}
16

17
return stoi(s);
18
}
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0