Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //User function Template for C++
- class Solution {
- public:
- int maximumNumber(int N) {
- string num = to_string(N);
- bool replaced = false;
- for (int i = 0; i < num.length(); i++) {
- if (num[i] == '7' && !replaced) {
- num[i] = '9';
- replaced = true;
- } else if (num[i] == '7' && replaced) {
- break;
- }
- }
- return stoi(num);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement