Advertisement
CR7CR7

problemOne

Jul 30th, 2023
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. //User function Template for C++
  2.  
  3.  
  4.  
  5. class Solution {
  6. public:
  7.     int maximumNumber(int N) {
  8.         string num = to_string(N);
  9.         bool replaced = false;
  10.         for (int i = 0; i < num.length(); i++) {
  11.             if (num[i] == '7' && !replaced) {
  12.                 num[i] = '9';
  13.                 replaced = true;
  14.             } else if (num[i] == '7' && replaced) {
  15.                 break;
  16.             }
  17.         }
  18.         return stoi(num);
  19.     }
  20. };
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement