File tree 3 files changed +55
-0
lines changed
solution/2800-2899/2898.Maximum Linear Stock Score
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,26 @@ func max(a, b int64) int64 {
147
147
}
148
148
```
149
149
150
+ ### ** Rust**
151
+
152
+ ``` rust
153
+ use std :: collections :: HashMap ;
154
+
155
+ impl Solution {
156
+ pub fn max_score (prices : Vec <i32 >) -> i64 {
157
+ let mut cnt : HashMap <i32 , i64 > = HashMap :: new ();
158
+
159
+ for (i , x ) in prices . iter (). enumerate () {
160
+ let key = (* x ) as i32 - (i as i32 );
161
+ let count = cnt . entry (key ). or_insert (0 );
162
+ * count += * x as i64 ;
163
+ }
164
+
165
+ * cnt . values (). max (). unwrap_or (& 0 )
166
+ }
167
+ }
168
+ ```
169
+
150
170
### ** TypeScript**
151
171
152
172
``` ts
Original file line number Diff line number Diff line change @@ -139,6 +139,26 @@ func max(a, b int64) int64 {
139
139
}
140
140
```
141
141
142
+ ### ** Rust**
143
+
144
+ ``` rust
145
+ use std :: collections :: HashMap ;
146
+
147
+ impl Solution {
148
+ pub fn max_score (prices : Vec <i32 >) -> i64 {
149
+ let mut cnt : HashMap <i32 , i64 > = HashMap :: new ();
150
+
151
+ for (i , x ) in prices . iter (). enumerate () {
152
+ let key = (* x ) as i32 - (i as i32 );
153
+ let count = cnt . entry (key ). or_insert (0 );
154
+ * count += * x as i64 ;
155
+ }
156
+
157
+ * cnt . values (). max (). unwrap_or (& 0 )
158
+ }
159
+ }
160
+ ```
161
+
142
162
### ** TypeScript**
143
163
144
164
``` ts
Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashMap ;
2
+
3
+ impl Solution {
4
+ pub fn max_score ( prices : Vec < i32 > ) -> i64 {
5
+ let mut cnt: HashMap < i32 , i64 > = HashMap :: new ( ) ;
6
+
7
+ for ( i, x) in prices. iter ( ) . enumerate ( ) {
8
+ let key = ( * x) as i32 - ( i as i32 ) ;
9
+ let count = cnt. entry ( key) . or_insert ( 0 ) ;
10
+ * count += * x as i64 ;
11
+ }
12
+
13
+ * cnt. values ( ) . max ( ) . unwrap_or ( & 0 )
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments