File tree Expand file tree Collapse file tree 5 files changed +150
-0
lines changed
solution/2400-2499/2496.Maximum Value of a String in an Array Expand file tree Collapse file tree 5 files changed +150
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,61 @@ func maximumValue(strs []string) (ans int) {
143
143
}
144
144
```
145
145
146
+ ### ** TypeScript**
147
+
148
+ ``` ts
149
+ function maximumValue(strs : string []): number {
150
+ let ans = 0 ;
151
+ for (const s of strs ) {
152
+ const num = Number (s );
153
+ ans = Math .max (ans , Number .isNaN (num ) ? s .length : num );
154
+ }
155
+ return ans ;
156
+ }
157
+ ```
158
+
159
+ ### ** Rust**
160
+
161
+ ``` rust
162
+ impl Solution {
163
+ pub fn maximum_value (strs : Vec <String >) -> i32 {
164
+ let mut ans = 0 ;
165
+ for s in strs . iter () {
166
+ let num = s . parse (). unwrap_or (s . len ());
167
+ ans = ans . max (num );
168
+ }
169
+ ans as i32
170
+ }
171
+ }
172
+ ```
173
+
174
+ ### ** C**
175
+
176
+ ``` c
177
+ #define max (a, b ) (((a) > (b)) ? (a) : (b))
178
+
179
+ int parseInt (char * s) {
180
+ int n = strlen(s);
181
+ int res = 0;
182
+ for (int i = 0; i < n; i++) {
183
+ if (!isdigit(s[ i] )) {
184
+ return n;
185
+ }
186
+ res = res * 10 + s[ i] - '0';
187
+ }
188
+ return res;
189
+ }
190
+
191
+ int maximumValue(char ** strs, int strsSize) {
192
+ int ans = 0;
193
+ for (int i = 0; i < strsSize; i++) {
194
+ int num = parseInt(strs[ i] );
195
+ ans = max(ans, num);
196
+ }
197
+ return ans;
198
+ }
199
+ ```
200
+
146
201
### **...**
147
202
148
203
```
Original file line number Diff line number Diff line change @@ -128,6 +128,61 @@ func maximumValue(strs []string) (ans int) {
128
128
}
129
129
```
130
130
131
+ ### ** TypeScript**
132
+
133
+ ``` ts
134
+ function maximumValue(strs : string []): number {
135
+ let ans = 0 ;
136
+ for (const s of strs ) {
137
+ const num = Number (s );
138
+ ans = Math .max (ans , Number .isNaN (num ) ? s .length : num );
139
+ }
140
+ return ans ;
141
+ }
142
+ ```
143
+
144
+ ### ** Rust**
145
+
146
+ ``` rust
147
+ impl Solution {
148
+ pub fn maximum_value (strs : Vec <String >) -> i32 {
149
+ let mut ans = 0 ;
150
+ for s in strs . iter () {
151
+ let num = s . parse (). unwrap_or (s . len ());
152
+ ans = ans . max (num );
153
+ }
154
+ ans as i32
155
+ }
156
+ }
157
+ ```
158
+
159
+ ### ** C**
160
+
161
+ ``` c
162
+ #define max (a, b ) (((a) > (b)) ? (a) : (b))
163
+
164
+ int parseInt (char * s) {
165
+ int n = strlen(s);
166
+ int res = 0;
167
+ for (int i = 0; i < n; i++) {
168
+ if (!isdigit(s[ i] )) {
169
+ return n;
170
+ }
171
+ res = res * 10 + s[ i] - '0';
172
+ }
173
+ return res;
174
+ }
175
+
176
+ int maximumValue(char ** strs, int strsSize) {
177
+ int ans = 0;
178
+ for (int i = 0; i < strsSize; i++) {
179
+ int num = parseInt(strs[ i] );
180
+ ans = max(ans, num);
181
+ }
182
+ return ans;
183
+ }
184
+ ```
185
+
131
186
### **...**
132
187
133
188
```
Original file line number Diff line number Diff line change
1
+ #define max (a , b ) (((a) > (b)) ? (a) : (b))
2
+
3
+ int parseInt (char * s ) {
4
+ int n = strlen (s );
5
+ int res = 0 ;
6
+ for (int i = 0 ; i < n ; i ++ ) {
7
+ if (!isdigit (s [i ])) {
8
+ return n ;
9
+ }
10
+ res = res * 10 + s [i ] - '0' ;
11
+ }
12
+ return res ;
13
+ }
14
+
15
+ int maximumValue (char * * strs , int strsSize ) {
16
+ int ans = 0 ;
17
+ for (int i = 0 ; i < strsSize ; i ++ ) {
18
+ int num = parseInt (strs [i ]);
19
+ ans = max (ans , num );
20
+ }
21
+ return ans ;
22
+ }
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn maximum_value ( strs : Vec < String > ) -> i32 {
3
+ let mut ans = 0 ;
4
+ for s in strs. iter ( ) {
5
+ let num = s. parse ( ) . unwrap_or ( s. len ( ) ) ;
6
+ ans = ans. max ( num) ;
7
+ }
8
+ ans as i32
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ function maximumValue ( strs : string [ ] ) : number {
2
+ let ans = 0 ;
3
+ for ( const s of strs ) {
4
+ const num = Number ( s ) ;
5
+ ans = Math . max ( ans , Number . isNaN ( num ) ? s . length : num ) ;
6
+ }
7
+ return ans ;
8
+ }
You can’t perform that action at this time.
0 commit comments