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 732169a

Browse files
solved: 3 Sum
1 parent 7f7afaa commit 732169a

File tree

2 files changed

+3112
-0
lines changed

2 files changed

+3112
-0
lines changed

‎README.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
<img src="https://github.com/lambiengcode/leetcode-solved-by-dart/blob/master/img/leetcode-dart.png?raw=true" width="100%" height="auto"/>
44

5+
## Table of Contents
6+
- [:lion: Leetcode :seedling:](#lion-leetcode-seedling)
7+
- [Table of Contents](#table-of-contents)
8+
- [String to Int - Atoi](#string-to-int---atoi)
9+
- [Is Palindrome](#is-palindrome)
10+
- [Regular Expression Matching](#regular-expression-matching)
11+
- [Container with most water](#container-with-most-water)
12+
- [Integer to Roman](#integer-to-roman)
13+
- [Validate Stack Sequences](#validate-stack-sequences)
14+
- [Reverse Nodes in k-Group](#reverse-nodes-in-k-group)
15+
- [Substring with Concatenation of All Words](#substring-with-concatenation-of-all-words)
16+
- [Longest Valid Parentheses](#longest-valid-parentheses)
17+
- [Merge k Sorted Lists](#merge-k-sorted-lists)
18+
- [Kids With the Greatest Number of Candies](#kids-with-the-greatest-number-of-candies)
19+
- [Sudoku Solver](#sudoku-solver)
20+
- [First Missing Positive](#first-missing-positive)
21+
- [Trapping rain water](#trapping-rain-water)
22+
- [Wildcard Matching](#wildcard-matching)
23+
- [N Queens](#n-queens)
24+
- [Valid number](#valid-number)
25+
- [Text Justification](#text-justification)
26+
- [3 Sum](#3-sum)
27+
528
### String to Int - Atoi
629

730
```dart
@@ -579,4 +602,41 @@ List<String> fillSpace(List<String> words, int maxWidth) {
579602
580603
return words;
581604
}
605+
```
606+
607+
### 3 Sum
608+
609+
```dart
610+
List<List<int>> threeSum(List<int> nums) {
611+
nums.sort();
612+
613+
final List<List<int>> result = [];
614+
615+
for (int i = 0; i < nums.length - 2; i++) {
616+
if (i > 0 && nums[i] == nums[i - 1]) continue;
617+
618+
int left = i + 1;
619+
int right = nums.length - 1;
620+
621+
while (left < right) {
622+
final int sum = nums[i] + nums[left] + nums[right];
623+
624+
if (sum == 0) {
625+
result.add([nums[i], nums[left], nums[right]]);
626+
627+
// remove duplicate
628+
while (left < nums.length - 1 && nums[left] == nums[left + 1]) left++;
629+
while (right > 0 && nums[right] == nums[right - 1]) right--;
630+
left++;
631+
right--;
632+
} else if (sum < 0) {
633+
left++;
634+
} else {
635+
right--;
636+
}
637+
}
638+
}
639+
640+
return result;
641+
}
582642
```

0 commit comments

Comments
(0)

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