Movatterモバイル変換


[0]ホーム

URL:


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

Commitc0ce207

Browse files
committed
Update all yesterday solution changes.
1 parent769165d commitc0ce207

File tree

64 files changed

+2956
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2956
-971
lines changed

‎en/1-1000/1-two-sum.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Visit original link:[leetcoder.net -LeetCoder: Fucking GoodLeetCode Solutions](https://leetcoder.net/en/leetcode/1-two-sum) for a better experience!
1+
Visit original link:[leetcoder.net -FuckLeetCode](https://leetcoder.net/en/leetcode/1-two-sum) for a better experience!
22

3-
#1. Two Sum - LeetCoder: Fucking Good LeetCode Solutions
3+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
4+
5+
#1. Two Sum - Fuck LeetCode
46

57
LeetCode link:[1. Two Sum](https://leetcode.com/problems/two-sum), difficulty:**Easy**.
68

@@ -325,4 +327,6 @@ class Solution:
325327

326328
Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
327329

328-
Original link: [leetcoder.net- LeetCoder: Fucking Good LeetCode Solutions](https://leetcoder.net/en/leetcode/1-two-sum).
330+
Original link: [leetcoder.net- Fuck LeetCode](https://leetcoder.net/en/leetcode/1-two-sum).
331+
332+
GitHub repo: [fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).

‎en/1-1000/15-3sum.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Visit original link:[leetcoder.net -LeetCoder: Fucking GoodLeetCode Solutions](https://leetcoder.net/en/leetcode/15-3sum) for a better experience!
1+
Visit original link:[leetcoder.net -FuckLeetCode](https://leetcoder.net/en/leetcode/15-3sum) for a better experience!
22

3-
#15. 3Sum - LeetCoder: Fucking Good LeetCode Solutions
3+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
4+
5+
#15. 3Sum - Fuck LeetCode
46

57
LeetCode link:[15. 3Sum](https://leetcode.com/problems/3sum), difficulty:**Medium**.
68

@@ -509,4 +511,6 @@ def duplicate_removed_nums(nums):
509511

510512
Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website [leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
511513

512-
Original link: [leetcoder.net- LeetCoder: Fucking Good LeetCode Solutions](https://leetcoder.net/en/leetcode/15-3sum).
514+
Original link: [leetcoder.net- Fuck LeetCode](https://leetcoder.net/en/leetcode/15-3sum).
515+
516+
GitHub repo: [fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).

‎en/1-1000/160-intersection-of-two-linked-lists.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Visit original link:[leetcoder.net -LeetCoder: Fucking GoodLeetCode Solutions](https://leetcoder.net/en/leetcode/160-intersection-of-two-linked-lists) for a better experience!
1+
Visit original link:[leetcoder.net -FuckLeetCode](https://leetcoder.net/en/leetcode/160-intersection-of-two-linked-lists) for a better experience!
22

3-
#160. Intersection of Two Linked Lists - LeetCoder: Fucking Good LeetCode Solutions
3+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
4+
5+
#160. Intersection of Two Linked Lists - Fuck LeetCode
46

57
LeetCode link:[160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists), difficulty:**Easy**.
68

@@ -495,4 +497,6 @@ func getIntersectionNode(headA, headB *ListNode) *ListNode {
495497

496498
Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website[leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
497499

498-
Original link:[leetcoder.net - LeetCoder: Fucking Good LeetCode Solutions](https://leetcoder.net/en/leetcode/160-intersection-of-two-linked-lists).
500+
Original link:[leetcoder.net - Fuck LeetCode](https://leetcoder.net/en/leetcode/160-intersection-of-two-linked-lists).
501+
502+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).

‎en/1-1000/18-4sum.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Visit original link:[leetcoder.net -LeetCoder: Fucking GoodLeetCode Solutions](https://leetcoder.net/en/leetcode/18-4sum) for a better experience!
1+
Visit original link:[leetcoder.net -FuckLeetCode](https://leetcoder.net/en/leetcode/18-4sum) for a better experience!
22

3-
#18. 4Sum - LeetCoder: Fucking Good LeetCode Solutions
3+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
4+
5+
#18. 4Sum - Fuck LeetCode
46

57
LeetCode link:[18. 4Sum](https://leetcode.com/problems/4sum), difficulty:**Medium**.
68

@@ -372,4 +374,6 @@ public class Solution {
372374

373375
Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website[leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
374376

375-
Original link:[leetcoder.net - LeetCoder: Fucking Good LeetCode Solutions](https://leetcoder.net/en/leetcode/18-4sum).
377+
Original link:[leetcoder.net - Fuck LeetCode](https://leetcoder.net/en/leetcode/18-4sum).
378+
379+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).

‎en/1-1000/19-remove-nth-node-from-end-of-list.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Visit original link:[leetcoder.net -LeetCoder: Fucking GoodLeetCode Solutions](https://leetcoder.net/en/leetcode/19-remove-nth-node-from-end-of-list) for a better experience!
1+
Visit original link:[leetcoder.net -FuckLeetCode](https://leetcoder.net/en/leetcode/19-remove-nth-node-from-end-of-list) for a better experience!
22

3-
#19. Remove Nth Node From End of List - LeetCoder: Fucking Good LeetCode Solutions
3+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
4+
5+
#19. Remove Nth Node From End of List - Fuck LeetCode
46

57
LeetCode link:[19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list), difficulty:**Medium**.
68

@@ -384,4 +386,6 @@ end
384386

385387
Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website[leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
386388

387-
Original link:[leetcoder.net - LeetCoder: Fucking Good LeetCode Solutions](https://leetcoder.net/en/leetcode/19-remove-nth-node-from-end-of-list).
389+
Original link:[leetcoder.net - Fuck LeetCode](https://leetcoder.net/en/leetcode/19-remove-nth-node-from-end-of-list).
390+
391+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).

‎en/1-1000/20-valid-parentheses.md

Lines changed: 233 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Visit original link:[leetcoder.net -LeetCoder: Fucking GoodLeetCode Solutions](https://leetcoder.net/en/leetcode/20-valid-parentheses) for a better experience!
1+
Visit original link:[leetcoder.net -FuckLeetCode](https://leetcoder.net/en/leetcode/20-valid-parentheses) for a better experience!
22

3-
#20. Valid Parentheses - LeetCoder: Fucking Good LeetCode Solutions
3+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).
4+
5+
#20. Valid Parentheses - Fuck LeetCode
46

57
LeetCode link:[20. Valid Parentheses](https://leetcode.com/problems/valid-parentheses), difficulty:**Easy**.
68

@@ -83,19 +85,33 @@ An input string is valid if:
8385
##JavaScript
8486

8587
```javascript
88+
/**
89+
*@param{string}s
90+
*@return{boolean}
91+
*/
8692
varisValid=function (s) {
87-
constrightToLeft=newMap([
93+
constcloseToOpen=newMap([
8894
[')','('],
8995
['}','{'],
9096
[']','['],
9197
])
9298
conststack= []
9399

94100
for (constcharof s) {
95-
if (!rightToLeft.has(char)) {
96-
stack.push(char)
97-
}elseif (stack.length===0||stack.pop()!=rightToLeft.get(char)) {
98-
returnfalse
101+
if (!closeToOpen.has(char)) {
102+
// is open bracket
103+
stack.push(char)
104+
continue
105+
}
106+
// is close bracket
107+
108+
if (stack.length===0) {
109+
returnfalse
110+
}
111+
112+
// stack top value doesn't match the expected value
113+
if (stack.pop()!=closeToOpen.get(char)) {
114+
returnfalse
99115
}
100116
}
101117

@@ -108,22 +124,226 @@ var isValid = function (s) {
108124
```python
109125
classSolution:
110126
defisValid(self,s:str) ->bool:
111-
right_to_left= {
127+
# Map closing brackets to their opening brackets
128+
close_to_open= {
112129
')':'(',
113130
'}':'{',
114131
']':'[',
115132
}
116133
stack= []
117134

118135
for charin s:
119-
if charnotin right_to_left:
136+
if charnotin close_to_open:
137+
# is open bracket
120138
stack.append(char)
121-
elifnot stackor stack.pop()!= right_to_left[char]:
139+
continue
140+
# is close bracket
141+
142+
ifnot stack:
143+
returnFalse
144+
145+
# stack top value doesn't match the expected value
146+
if stack.pop()!= close_to_open[char]:
122147
returnFalse
123148

124149
returnnot stack
125150
```
126151

152+
##Java
153+
154+
```java
155+
classSolution {
156+
publicbooleanisValid(Strings) {
157+
// Map closing brackets to their opening brackets
158+
var closeToOpen=newHashMap<Character,Character>();
159+
closeToOpen.put(')','(');
160+
closeToOpen.put('}','{');
161+
closeToOpen.put(']','[');
162+
163+
var stack=newStack<Character>();
164+
165+
for (char c: s.toCharArray()) {
166+
if (!closeToOpen.containsKey(c)) {
167+
// is open bracket
168+
stack.push(c);
169+
continue;
170+
}
171+
// is close bracket
172+
173+
if (stack.isEmpty()) {
174+
returnfalse;
175+
}
176+
177+
// stack top value doesn't match the expected value
178+
if (stack.pop()!= closeToOpen.get(c)) {
179+
returnfalse;
180+
}
181+
}
182+
183+
return stack.isEmpty();
184+
}
185+
}
186+
```
187+
188+
##C++
189+
190+
```cpp
191+
classSolution {
192+
public:
193+
bool isValid(string s) {
194+
// Map closing brackets to their opening brackets
195+
unordered_map<char, char> closeToOpen = {
196+
{')', '('},
197+
{'}', '{'},
198+
{']', '['}
199+
};
200+
201+
stack<char> st;
202+
203+
for (char c : s) {
204+
if (closeToOpen.find(c) == closeToOpen.end()) {
205+
// is open bracket
206+
st.push(c);
207+
continue;
208+
}
209+
// is close bracket
210+
211+
if (st.empty()) {
212+
return false;
213+
}
214+
215+
// stack top value doesn't match the expected value
216+
if (st.top() != closeToOpen[c]) {
217+
return false;
218+
}
219+
220+
st.pop();
221+
}
222+
223+
return st.empty();
224+
}
225+
};
226+
```
227+
228+
## C#
229+
230+
```csharp
231+
public class Solution
232+
{
233+
public bool IsValid(string s)
234+
{
235+
// Map closing brackets to their opening brackets
236+
var closeToOpen = new Dictionary<char, char>()
237+
{
238+
{')', '('},
239+
{'}', '{'},
240+
{']', '['}
241+
};
242+
243+
var stack = new Stack<char>();
244+
245+
foreach (char c in s) {
246+
if (!closeToOpen.ContainsKey(c))
247+
{
248+
// is open bracket
249+
stack.Push(c);
250+
continue;
251+
}
252+
// is close bracket
253+
254+
if (stack.Count == 0)
255+
{
256+
return false;
257+
}
258+
259+
// stack top value doesn't match the expected value
260+
if (stack.Pop() != closeToOpen[c])
261+
{
262+
return false;
263+
}
264+
}
265+
266+
return stack.Count == 0;
267+
}
268+
}
269+
```
270+
271+
##Go
272+
273+
```go
274+
funcisValid(sstring)bool {
275+
// Map closing brackets to their opening brackets
276+
closeToOpen:=map[rune]rune{
277+
')':'(',
278+
'}':'{',
279+
']':'[',
280+
}
281+
282+
stack:= []rune{}
283+
284+
for_,char:=range s {
285+
if_,isClose:= closeToOpen[char]; !isClose {
286+
// is open bracket
287+
stack =append(stack, char)
288+
continue
289+
}
290+
// is close bracket
291+
292+
iflen(stack) ==0 {
293+
returnfalse
294+
}
295+
296+
lastChar:= stack[len(stack) -1]
297+
298+
// stack top value doesn't match the expected value
299+
if lastChar != closeToOpen[char] {
300+
returnfalse
301+
}
302+
303+
stack = stack[:len(stack) -1]// pop operation
304+
}
305+
306+
returnlen(stack) ==0
307+
}
308+
```
309+
310+
##Ruby
311+
312+
```ruby
313+
#@param {String} s
314+
#@return {Boolean}
315+
defis_valid(s)
316+
# Map closing brackets to their opening brackets
317+
close_to_open= {
318+
')' =>'(',
319+
'}' =>'{',
320+
']' =>'['
321+
}
322+
323+
stack= []
324+
325+
s.each_chardo |char|
326+
if!close_to_open.key?(char)
327+
# is open bracket
328+
stack.push(char)
329+
next
330+
end
331+
# is close bracket
332+
333+
if stack.empty?
334+
returnfalse
335+
end
336+
337+
# stack top value doesn't match the expected value
338+
if stack.pop!= close_to_open[char]
339+
returnfalse
340+
end
341+
end
342+
343+
stack.empty?
344+
end
345+
```
346+
127347
##Other languages
128348

129349
```java
@@ -132,4 +352,6 @@ class Solution:
132352

133353
Dear LeetCoders! For a better LeetCode problem-solving experience, please visit website[leetcoder.net](https://leetcoder.net): Dare to claim the best practices of LeetCode solutions! Will save you a lot of time!
134354

135-
Original link:[leetcoder.net - LeetCoder: Fucking Good LeetCode Solutions](https://leetcoder.net/en/leetcode/20-valid-parentheses).
355+
Original link:[leetcoder.net - Fuck LeetCode](https://leetcoder.net/en/leetcode/20-valid-parentheses).
356+
357+
GitHub repo:[fuck-leetcode](https://github.com/fuck-leetcode/fuck-leetcode).

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp