Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dfc2f37

Browse files
solved: Trapping rain water
1 parent e40e2dd commit dfc2f37

16 files changed

+74
-5
lines changed

‎README.md‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## :lion: Leetcode
1+
## :lion: Leetcode:seedling:
22

33
### String to Int - Atoi
44

@@ -403,4 +403,34 @@ int firstMissingPositive(List<int> nums) {
403403
404404
return nums.last + 1;
405405
}
406+
```
407+
408+
### Trapping rain water
409+
410+
```dart
411+
int trap(List<int> height) {
412+
if (height.length < 2) return 0;
413+
414+
List<int> left = List.generate(height.length, (index) => 0);
415+
416+
List<int> right = List.generate(height.length, (index) => 0);
417+
418+
int result = 0;
419+
420+
left.first = height.first;
421+
for (int i = 1; i < height.length; i++) {
422+
left[i] = max(left[i - 1], height[i]);
423+
}
424+
425+
right.last = height.last;
426+
for (int i = height.length - 2; i >= 0; i--) {
427+
right[i] = max(right[i + 1], height[i]);
428+
}
429+
430+
for (int i = 0; i < height.length; i++) {
431+
result += min(left[i], right[i]) - height[i];
432+
}
433+
434+
return result;
435+
}
406436
```

‎img/LeetCode.jpeg‎

10.9 KB
Loading[フレーム]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:math';
22

3-
import 'helpers/stop_watch.dart';
3+
import '../helpers/stop_watch.dart';
44

55
void main(List<String> args) {
66
List<List<int>> cases = [
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import 'helpers/list_node_helper.dart';
2-
import 'models/list_node.dart';
1+
import '../helpers/list_node_helper.dart';
2+
import '../models/list_node.dart';
33

44
void main(List<String> args) {
55
List<List<List<int>>> cases = [

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /