Skip to content

Commit c51b751

Browse files
authored
Create Maximum Value after Insertion.java
1 parent 8f44016 commit c51b751

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public String maxValue(String n, int x) {
3+
if (n.charAt(0) == '-') {
4+
for (int i = 1; i < n.length(); i++) {
5+
if (Character.getNumericValue(n.charAt(i)) > x) {
6+
return "-" + n.substring(1, i) + x + n.substring(i);
7+
}
8+
}
9+
} else {
10+
for (int i = 0; i < n.length(); i++) {
11+
if (Character.getNumericValue(n.charAt(i)) < x) {
12+
return n.substring(0, i) + x + n.substring(i);
13+
}
14+
}
15+
}
16+
return n + x;
17+
}
18+
}

0 commit comments

Comments
 (0)