Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f830207

Browse files
solved leetcode daily challenge, Largest_Number_After_Mutating_Substring/
1 parent ae6c52b commit f830207

File tree

1 file changed

+62
-0
lines changed
  • LeetCode/Largest_Number_After_Mutating_Substring

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START
7+
/*
8+
## Largest Number After Mutating Substring
9+
10+
*/
11+
12+
class Solution {
13+
public:
14+
string maximumNumber(string num, vector<int> &change) {
15+
bool muted = false;
16+
bool lastM = false;
17+
bool changed = false;
18+
for (int i = 0; i < num.size(); i++) {
19+
int ori = num[i] - '0';
20+
int af = change[ori];
21+
if ((!muted || lastM || !changed) && af >= ori) {
22+
num[i] += af - ori;
23+
if (af != ori) changed = true;
24+
lastM = true;
25+
muted = true;
26+
} else {
27+
lastM = false;
28+
}
29+
}
30+
return num;
31+
}
32+
};
33+
34+
//// END
35+
struct T {
36+
37+
};
38+
39+
TEST(Solution, test) {
40+
T ts[] = {
41+
{
42+
43+
},
44+
{
45+
46+
},
47+
48+
};
49+
50+
for (T t : ts) {
51+
Solution solution;
52+
53+
}
54+
}
55+
56+
int main() {
57+
testing::InitGoogleTest();
58+
59+
return RUN_ALL_TESTS();
60+
}
61+
62+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /