File tree Expand file tree Collapse file tree 4 files changed +107
-0
lines changed
solution/0000-0099/0011.Container With Most Water Expand file tree Collapse file tree 4 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,45 @@ var maxArea = function (height) {
174
174
};
175
175
```
176
176
177
+ ### ** TypeScript**
178
+
179
+ ``` ts
180
+ function maxArea(height : number []): number {
181
+ const n = height .length ;
182
+ let res = 0 ;
183
+ for (let i = 0 ; i < n - 1 ; i ++ ) {
184
+ for (let j = n - 1 ; j >= 0 ; j -- ) {
185
+ if (height [i ] * (j - i ) < res ) {
186
+ break ;
187
+ }
188
+ res = Math .max (res , Math .min (height [i ], height [j ]) * (j - i ));
189
+ }
190
+ }
191
+ return res ;
192
+ }
193
+ ```
194
+
195
+ ### ** Rust**
196
+
197
+ ``` rust
198
+ impl Solution {
199
+ pub fn max_area (height : Vec <i32 >) -> i32 {
200
+ let mut i = 0 ;
201
+ let mut j = height . len () - 1 ;
202
+ let mut res = 0 ;
203
+ while i < j {
204
+ res = res . max (height [i ]. min (height [j ]) * (j - i ) as i32 );
205
+ if height [i ] <= height [j ] {
206
+ i += 1 ;
207
+ } else {
208
+ j -= 1 ;
209
+ }
210
+ }
211
+ res
212
+ }
213
+ }
214
+ ```
215
+
177
216
### ** ...**
178
217
179
218
```
Original file line number Diff line number Diff line change @@ -149,6 +149,45 @@ var maxArea = function (height) {
149
149
};
150
150
```
151
151
152
+ ### ** TypeScript**
153
+
154
+ ``` ts
155
+ function maxArea(height : number []): number {
156
+ const n = height .length ;
157
+ let res = 0 ;
158
+ for (let i = 0 ; i < n - 1 ; i ++ ) {
159
+ for (let j = n - 1 ; j >= 0 ; j -- ) {
160
+ if (height [i ] * (j - i ) < res ) {
161
+ break ;
162
+ }
163
+ res = Math .max (res , Math .min (height [i ], height [j ]) * (j - i ));
164
+ }
165
+ }
166
+ return res ;
167
+ }
168
+ ```
169
+
170
+ ### ** Rust**
171
+
172
+ ``` rust
173
+ impl Solution {
174
+ pub fn max_area (height : Vec <i32 >) -> i32 {
175
+ let mut i = 0 ;
176
+ let mut j = height . len () - 1 ;
177
+ let mut res = 0 ;
178
+ while i < j {
179
+ res = res . max (height [i ]. min (height [j ]) * (j - i ) as i32 );
180
+ if height [i ] <= height [j ] {
181
+ i += 1 ;
182
+ } else {
183
+ j -= 1 ;
184
+ }
185
+ }
186
+ res
187
+ }
188
+ }
189
+ ```
190
+
152
191
### ** ...**
153
192
154
193
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn max_area ( height : Vec < i32 > ) -> i32 {
3
+ let mut i = 0 ;
4
+ let mut j = height. len ( ) - 1 ;
5
+ let mut res = 0 ;
6
+ while i < j {
7
+ res = res. max ( height[ i] . min ( height[ j] ) * ( j - i) as i32 ) ;
8
+ if height[ i] <= height[ j] {
9
+ i += 1 ;
10
+ } else {
11
+ j -= 1 ;
12
+ }
13
+ }
14
+ res
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ function maxArea ( height : number [ ] ) : number {
2
+ const n = height . length ;
3
+ let res = 0 ;
4
+ for ( let i = 0 ; i < n - 1 ; i ++ ) {
5
+ for ( let j = n - 1 ; j >= 0 ; j -- ) {
6
+ if ( height [ i ] * ( j - i ) < res ) {
7
+ break ;
8
+ }
9
+ res = Math . max ( res , Math . min ( height [ i ] , height [ j ] ) * ( j - i ) ) ;
10
+ }
11
+ }
12
+ return res ;
13
+ }
You can’t perform that action at this time.
0 commit comments