-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1323.cpp
More file actions
40 lines (36 loc) · 716 Bytes
/
1323.cpp
File metadata and controls
40 lines (36 loc) · 716 Bytes
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
35
36
37
38
39
40
class Solution {
public:
int maximum69Number (int num) {
vector<int>A;
while(num!=0)
{
int ll;
ll=num%10;
if(ll!=0)
{
A.push_back(ll);
}
num=num/10;
}
int m;
m=A.size();
for(int i=m-1;i>=0;i--)
{
if(A[i]==6)
{
A[i]=9;
break;
}
}
int k=0;
int ss=m;
int hh=1;
for(int j=m-1;j>=0;j--)
{
int vv=pow(10,(ss-hh));
k=k+(A[j]*vv);
hh=hh+1;
}
return k;
}
};