Skip to content

Commit

Permalink
2019-07-27
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Jul 27, 2019
1 parent e527ebf commit ad48516
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 0214.最短回文串/0214-最短回文串.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution(object):
def shortestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
reversedS = s[::-1]
i = 0
for i in range(len(s)):
if reversedS[i:] == s[:len(s) - i]:
return reversedS[:i] + s
return ""
19 changes: 19 additions & 0 deletions 0220.存在重复元素III/0220-存在重复元素III.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution(object):
def containsNearbyAlmostDuplicate(self, nums, k, t):
"""
:type nums: List[int]
:type k: int
:type t: int
:rtype: bool
"""
record = []
for i, num in enumerate(nums):
record.append([num, i])
record.sort()
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if record[j][0] - record[i][0] > t:
break
if abs(record[i][1] - record[j][1]) <= k:
return True
return False

0 comments on commit ad48516

Please sign in to comment.