8000 update at 2019-07-25 · Frantol910/leetcode@a51c4a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a51c4a6

Browse files
committed
update at 2019-07-25
1 parent 98963c0 commit a51c4a6

File tree

11 files changed

+251
-81
lines changed

11 files changed

+251
-81
lines changed

README.md

Lines changed: 12 10000 4 additions & 38 deletions
Large diffs are not rendered by default.

solutions/0001-two-sum/two-sum.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# return [0, 1].
1515
#
1616
#
17-
#  
18-
#
1917

2018

2119
class Solution(object):

solutions/0001-two-sum/two-sum.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// return [0, 1].
1212
//
1313
//
14-
//  
15-
//
1614

1715

1816
use std::collections::HashMap;

solutions/0003-longest-substring-without-repeating-characters/longest-substring-without-repeating-characters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#
3434
#
3535
#
36+
#
3637

3738

3839
class Solution(object):

solutions/0010-regular-expression-matching/regular-expression-matching.py

Lines changed: 36 addition 8000 s & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
4+
# Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
55
#
66
#
7-
# '.' Matches any single character.
8-
# '*' Matches zero or more of the preceding element.
7+
# '.' Matches any single character.
8+
# '*' Matches zero or more of the preceding element.
99
#
1010
#
11-
# The matching should cover the entire input string (not partial).
11+
# The matching should cover the entire input string (not partial).
1212
#
13-
# Note:
13+
# Note:
1414
#
1515
#
16-
# s could be empty and contains only lowercase letters a-z.
17-
# p could be empty and contains only lowercase letters a-z, and characters like . or *.
16+
# s could be empty and contains only lowercase letters a-z.
17+
# p could be empty and contains only lowercase letters a-z, and characters like . or *.
1818
#
1919
#
20-
# Example 1:
20+
# Example 1:
2121
#
2222
#
23-
# Input:
24-
# s = "aa"
25-
# p = "a"
26-
# Output: false
27-
# Explanation: "a" does not match the entire string "aa".
23+
# Input:
24+
# s = "aa"
25+
# p = "a"
26+
# Output: false
27+
# Explanation: "a" does not match the entire string "aa".
2828
#
2929
#
30-
# Example 2:
30+
# Example 2:
3131
#
3232
#
33-
# Input:
34-
# s = "aa"
35-
# p = "a*"
36-
# Output: true
37-
# Explanation: '*' means zero or more of the precedeng element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
33+
# Input:
34+
# s = "aa"
35+
# p = "a*"
36+
# Output: true
37+
# Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
3838
#
3939
#
40-
# Example 3:
40+
# Example 3:
4141
#
4242
#
43-
# Input:
44-
# s = "ab"
45-
# p = ".*"
46-
# Output: true
47-
# Explanation: ".*" means "zero or more (*) of any character (.)".
43+
# Input:
44+
# s = "ab"
45+
# p = ".*"
46+
# Output: true
47+
# Explanation: ".*" means "zero or more (*) of any character (.)".
4848
#
4949
#
50-
# Example 4:
50+
# Example 4:
5151
#
5252
#
53-
# Input:
54-
# s = "aab"
55-
# p = "c*a*b"
56-
# Output: true
57-
# Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore it matches "aab".
53+
# Input:
54+
# s = "aab"
55+
# p = "c*a*b"
56+
# Output: true
57+
# Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab".
5858
#
5959
#
60-
# Example 5:
60+
# Example 5:
6161
#
6262
#
63-
# Input:
64-
# s = "mississippi"
65-
# p = "mis*is*p*."
66-
# Output: false
63+
# Input:
64+
# s = "mississippi"
65+
# p = "mis*is*p*."
66+
# Output: false
6767
#
6868
#
6969

solutions/0056-merge-intervals/merge-intervals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# Output: [[1,5]]
1919
# Explanation: Intervals [1,4] and [4,5] are considered overlapping.
2020
#
21+
# NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
22+
#
2123

2224

2325
# Definition for an interval.

solutions/0057-insert-interval/insert-interval.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# Output: [[1,2],[3,10],[12,16]]
2020
# Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
2121
#
22+
# NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
23+
#
2224

2325

2426
# Definition for an interval.

solutions/0058-length-of-last-word/length-of-last-word.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
#
1010
# Example:
1111
#
12+
#
1213
# Input: "Hello World"
1314
# Output: 5
1415
#
1516
#
17+
#  
18+
#
1619

1720

1821
class Solution(object):

solutions/0101-symmetric-tree/symmetric-tree.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
# Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
55
#
6-
#
76
# For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
87
#
8+
#
99
# 1
1010
# / \
1111
# 2 2
1212
# / \ / \
1313
# 3 4 4 3
1414
#
1515
#
16+
#  
17+
#
18+
# But the following [1,2,2,null,3,null,3] is not:
1619
#
17-
# But the following [1,2,2,null,3,null,3] is not:
1820
#
1921
# 1
2022
# / \
@@ -23,7 +25,7 @@
2325
# 3 3
2426
#
2527
#
26-
#
28+
#  
2729
#
2830
# Note:
2931
# Bonus points if you could solve it both recursively and iteratively.
Lines changed: 77 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- coding:utf-8 -*-
2+
3+
4+
# Given a linked list, determine if it has a cycle in it.
5+
#
6+
# To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.
7+
#
8+
#  
9+
#
10+
#
11+
# Example 1:
12+
#
13+
#
14+
# Input: head = [3,2,0,-4], pos = 1
15+
# Output: true
16+
# Explanation: There is a cycle in the linked list, where tail connects to the second node.
17+
#
18+
#
19+
#
20+
#
21+
#
22+
#
23+
# Example 2:
24+
#
25+
#
26+
# Input: head = [1,2], pos = 0
27+
# Output: true
28+
# Explanation: There is a cycle in the linked list, where tail connects to the first node.
29+
#
30+
#
31+
#
32+
#
33+
#
34+
#
35+
# Example 3:
36+
#
37+
#
38+
# Input: head = [1], pos = -1
39+
# Output: false
40+
# Explanation: There is no cycle in the linked list.
41+
#
42+
#
43+
#
44+
#
45+
#
46+
#  
47+
#
48+
# Follow up:
49+
#
50+
# Can you solve it using O(1) (i.e. constant) memory?
51+
#
52+
53+
54+
# Definition for singly-linked list.
55+
# class ListNode(object):
56+
# def __init__(self, x):
57+
# self.val = x
58+
# self.next = None
59+
60+
class Solution(object):
61+
def hasCycle(self, head):
62+
"""
63+
:type head: ListNode
64+
:rtype: bool
65+
"""
66+
if head is None:
67+
return False
68+
cur = head
69+
dct = {}
70+
while cur.next:
71+
if id(cur) in dct:
72+
return True
73+
dct[id(cur)] = cur
74+
cur = cur.next
75+
76+
return False
77+

0 commit comments

Comments
 (0)
0