From 724de88ed66b006d797948a9c393b4d8659e86c8 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 26 Jan 2020 21:43:57 -0500 Subject: [PATCH] 2020-01-26 --- ...17\345\233\236\346\226\207\344\270\262.py" | 15 +++++++++ ...22\347\272\277\346\216\222\345\272\217.py" | 33 +++++++++++++++++++ ...17\345\217\267\350\275\254\346\215\242.py" | 19 +++++++++++ ...07\345\255\220\345\272\217\345\210\227.py" | 9 +++++ 4 files changed, 76 insertions(+) create mode 100644 "1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" create mode 100644 "1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" create mode 100644 "1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" create mode 100644 "1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" diff --git "a/1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" "b/1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..2cb31d9 --- /dev/null +++ "b/1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,15 @@ +class Solution(object): + def breakPalindrome(self, palindrome): + """ + :type palindrome: str + :rtype: str + """ + if len(palindrome) == 1: + return "" + if len(set(palindrome)) == 1: + if palindrome[0] == "a": + return palindrome[:-1] + "b" + for ch in palindrome: + if ord(ch) > ord("a"): + res = palindrome.replace(ch, "a", 1) + return res if res != res[::-1] else palindrome[:-1] + "b" \ No newline at end of file diff --git "a/1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" "b/1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" new file mode 100644 index 0000000..2c56a37 --- /dev/null +++ "b/1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" @@ -0,0 +1,33 @@ +class Solution(object): + def diagonalSort(self, mat): + """ + :type mat: List[List[int]] + :rtype: List[List[int]] + """ + if not mat or not mat[0]: + return None + m, n = len(mat), len(mat[0]) + for j in range(n): + i, l, pos = 0, [], [] + while i < m and j < n: + l.append(mat[i][j]) + pos.append([i, j]) + i += 1 + j += 1 + l.sort() + for i, p in enumerate(pos): + x, y = p + mat[x][y] = l[i] + + for i in range(1, m): + j, l, pos = 0, [], [] + while i < m and j < n: + l.append(mat[i][j]) + pos.append([i, j]) + i += 1 + j += 1 + l.sort() + for i, p in enumerate(pos): + x, y = p + mat[x][y] = l[i] + return mat \ No newline at end of file diff --git "a/1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" "b/1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" new file mode 100644 index 0000000..498c69d --- /dev/null +++ "b/1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" @@ -0,0 +1,19 @@ +class Solution(object): + def arrayRankTransform(self, arr): + """ + :type arr: List[int] + :rtype: List[int] + """ + l = sorted(arr) + dic, rank = {}, 0 + pre_num = None + for i, num in enumerate(l): + if pre_num != num: + rank += 1 + dic[num] = rank + pre_num = num + + res = [] + for num in arr: + res.append(dic[num]) + return res \ No newline at end of file diff --git "a/1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" "b/1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" new file mode 100644 index 0000000..2789ca8 --- /dev/null +++ "b/1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" @@ -0,0 +1,9 @@ +class Solution(object): + def removePalindromeSub(self, s): + """ + :type s: str + :rtype: int + """ + if not s: + return 0 + return 1 if s == s[::-1] else 2 \ No newline at end of file