Skip to content

Commit

Permalink
2020-01-26
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Jan 27, 2020
1 parent 311f339 commit 724de88
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 1328.破坏回文串/1328-破坏回文串.py
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions 1331.数组序号转换/1331-数组序号转换.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions 1332.删除回文子序列/1332-删除回文子序列.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 724de88

Please sign in to comment.