You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given an integer array nums, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`.
9
6
10
7
Notice that the solution set must not contain duplicate triplets.
11
8
12
-
Difficulty: **Medium**
13
-
14
9
### [Example 1]
15
10
**Input**: `nums = [-1,0,1,2,-1,-4]`
16
11
@@ -43,6 +38,7 @@ Notice that the order of the output and the order of the triplets does not matte
43
38
-`3 <= nums.length <= 3000`
44
39
-`-10**5 <= nums[i] <= 10**5`
45
40
41
+
### [Hints]
46
42
<details>
47
43
<summary>Hint 1</summary>
48
44
So, we essentially need to find three numbers x, y, and z such that they add up to the given value. If we fix one of the numbers say x, we are left with the two-sum problem at hand!
@@ -59,8 +55,6 @@ Notice that the order of the output and the order of the triplets does not matte
59
55
</details>
60
56
61
57
## Intuition
62
-
[中文题解](#中文题解)
63
-
64
58
1. The `sum` of three numbers equals `0`, which is equivalent to the `sum` of _two numbers_ equaling the _**negative** third number_.
65
59
2. There are two options:
66
60
1. First `determine two numbers` and `find the third number`
@@ -92,12 +86,6 @@ for (i = 0; i < nums.length; i++) {
92
86
* Time: `O(N * N)`.
93
87
* Space: `O(N)`.
94
88
95
-
## Java
96
-
```java
97
-
// Welcome to create a PR to complete the code of this language, thanks!
98
-
```
99
-
100
-
101
89
## Python
102
90
### Solution 1: Use Map (complex and slow)
103
91
```python
@@ -178,6 +166,11 @@ class Solution:
178
166
// Welcome to create a PR to complete the code of this language, thanks!
179
167
```
180
168
169
+
## Java
170
+
```java
171
+
// Welcome to create a PR to complete the code of this language, thanks!
172
+
```
173
+
181
174
## JavaScript
182
175
```javascript
183
176
// Welcome to create a PR to complete the code of this language, thanks!
@@ -198,77 +191,7 @@ class Solution:
198
191
# Welcome to create a PR to complete the code of this language, thanks!
199
192
```
200
193
201
-
## C
202
-
```c
203
-
// Welcome to create a PR to complete the code of this language, thanks!
204
-
```
205
-
206
-
## Kotlin
207
-
```kotlin
208
-
// Welcome to create a PR to complete the code of this language, thanks!
209
-
```
210
-
211
-
## Swift
212
-
```swift
213
-
// Welcome to create a PR to complete the code of this language, thanks!
194
+
## C, Kotlin, Swift, Rust or other languages
214
195
```
215
-
216
-
## Rust
217
-
```rust
218
196
// Welcome to create a PR to complete the code of this language, thanks!
219
197
```
220
-
221
-
## Other languages
222
-
```
223
-
// Welcome to create a PR to complete the code of this language, thanks!
- 239 https://leetcode.cn/problems/sliding-window-maximum/ tag `monotonic queue`
69
69
- 347 https://leetcode.cn/problems/top-k-frequent-elements/ tag `heap sort`
70
-
-
71
-
# Features
72
-
* Add Google translate as a link. Link example: https://github-com.translate.goog/gazeldx/leetcode-solutions/blob/main/solutions/1-1000/122-best-time-to-buy-and-sell-stock-ii.md?_x_tr_sl=auto&_x_tr_tl=zh-CN&_x_tr_hl=en&_x_tr_pto=wapp
0 commit comments