File tree 3 files changed +64
-0
lines changed
solution/1800-1899/1881.Maximum Value after Insertion
3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,29 @@ class Solution {
108
108
}
109
109
```
110
110
111
+ ### ** JavaScript**
112
+
113
+ ``` js
114
+ /**
115
+ * @param {string} n
116
+ * @param {number} x
117
+ * @return {string}
118
+ */
119
+ var maxValue = function (n , x ) {
120
+ let nums = [... n];
121
+ let sign = 1 , i = 0 ;
122
+ if (nums[0 ] == ' -' ) {
123
+ sign = - 1 ;
124
+ i++ ;
125
+ }
126
+ while (i < n .length && (nums[i] - x) * sign >= 0 ) {
127
+ i++ ;
128
+ }
129
+ nums .splice (i, 0 , x);
130
+ return nums .join (' ' );
131
+ };
132
+ ```
133
+
111
134
### ** ...**
112
135
113
136
```
Original file line number Diff line number Diff line change @@ -98,6 +98,29 @@ class Solution {
98
98
}
99
99
```
100
100
101
+ ### ** JavaScript**
102
+
103
+ ``` js
104
+ /**
105
+ * @param {string} n
106
+ * @param {number} x
107
+ * @return {string}
108
+ */
109
+ var maxValue = function (n , x ) {
110
+ let nums = [... n];
111
+ let sign = 1 , i = 0 ;
112
+ if (nums[0 ] == ' -' ) {
113
+ sign = - 1 ;
114
+ i++ ;
115
+ }
116
+ while (i < n .length && (nums[i] - x) * sign >= 0 ) {
117
+ i++ ;
118
+ }
119
+ nums .splice (i, 0 , x);
120
+ return nums .join (' ' );
121
+ };
122
+ ```
123
+
101
124
### ** ...**
102
125
103
126
```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } n
3
+ * @param {number } x
4
+ * @return {string }
5
+ */
6
+ var maxValue = function ( n , x ) {
7
+ let nums = [ ...n ] ;
8
+ let sign = 1 , i = 0 ;
9
+ if ( nums [ 0 ] == '-' ) {
10
+ sign = - 1 ;
11
+ i ++ ;
12
+ }
13
+ while ( i < n . length && ( nums [ i ] - x ) * sign >= 0 ) {
14
+ i ++ ;
15
+ }
16
+ nums . splice ( i , 0 , x ) ;
17
+ return nums . join ( '' ) ;
18
+ } ;
You can’t perform that action at this time.
0 commit comments