Skip to content

Commit 72459a8

Browse files
committed
2019-06-02
1 parent e806fbd commit 72459a8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution(object):
2+
def isMatch(self, s, p):
3+
"""
4+
:type s: str
5+
:type p: str
6+
:rtype: bool
7+
"""
8+
if not p: #Èç¹ûpΪ¿Õ£¬s²»¿Õ£¬return false£¬ s¿Õ, return true
9+
return not s
10+
11+
match = s and p[0] in [s[0], "."]
12+
if len(p) > 1 and p[1] == "*":
13+
return self.isMatch(s, p[2:]) or (match and self.isMatch(s[1:], p))
14+
return match and self.isMatch(s[1:], p[1:])
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution(object):
2+
def threeSumClosest(self, nums, target):
3+
"""
4+
:type nums: List[int]
5+
:type target: int
6+
:rtype: int
7+
"""
8+
nums.sort()
9+
res = nums[0] + nums[1] + nums[2]
10+
for i, num in enumerate(nums):
11+
left, right = i + 1, len(nums) - 1
12+
13+
while left < right:
14+
s = num + nums[left] + nums[right]
15+
# print s, res, abs(s - target), abs(res - target)
16+
if abs(s - target) < abs(res - target):
17+
res = s
18+
if s == target:
19+
return s
20+
elif s < target:
21+
left += 1
22+
else:
23+
right -= 1
24+
return res
25+
26+
27+

0 commit comments

Comments
 (0)