From ad48516c41be7eda4881051aa1cbf7b6cb8a4468 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sat, 27 Jul 2019 23:38:49 +0800 Subject: [PATCH] 2019-07-27 --- ...55\345\233\236\346\226\207\344\270\262.py" | 12 ++++++++++++ ...345\244\215\345\205\203\347\264\240III.py" | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 "0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" create mode 100644 "0220.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III/0220-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III.py" diff --git "a/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" "b/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..5f42c1c --- /dev/null +++ "b/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" @@ -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 "" \ No newline at end of file diff --git "a/0220.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III/0220-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III.py" "b/0220.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III/0220-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III.py" new file mode 100644 index 0000000..80ba576 --- /dev/null +++ "b/0220.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III/0220-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240III.py" @@ -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 \ No newline at end of file