File tree 4 files changed +76
-0
lines changed
4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def breakPalindrome (self , palindrome ):
3
+ """
4
+ :type palindrome: str
5
+ :rtype: str
6
+ """
7
+ if len (palindrome ) == 1 :
8
+ return ""
9
+ if len (set (palindrome )) == 1 :
10
+ if palindrome [0 ] == "a" :
11
+ return palindrome [:- 1 ] + "b"
12
+ for ch in palindrome :
13
+ if ord (ch ) > ord ("a" ):
14
+ res = palindrome .replace (ch , "a" , 1 )
15
+ return res if res != res [::- 1 ] else palindrome [:- 1 ] + "b"
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def diagonalSort (self , mat ):
3
+ """
4
+ :type mat: List[List[int]]
5
+ :rtype: List[List[int]]
6
+ """
7
+ if not mat or not mat [0 ]:
8
+ return None
9
+ m , n = len (mat ), len (mat [0 ])
10
+ for j in range (n ):
11
+ i , l , pos = 0 , [], []
12
+ while i < m and j < n :
13
+ l .append (mat [i ][j ])
14
+ pos .append ([i , j ])
15
+ i += 1
16
+ j += 1
17
+ l .sort ()
18
+ for i , p in enumerate (pos ):
19
+ x , y = p
20
+ mat [x ][y ] = l [i ]
21
+
22
+ for i in range (1 , m ):
23
+ j , l , pos = 0 , [], []
24
+ while i < m and j < n :
25
+ l .append (mat [i ][j ])
26
+ pos .append ([i , j ])
27
+ i += 1
28
+ j += 1
29
+ l .sort ()
30
+ for i , p in enumerate (pos ):
31
+ x , y = p
32
+ mat [x ][y ] = l [i ]
33
+ return mat
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def arrayRankTransform (self , arr ):
3
+ """
4
+ :type arr: List[int]
5
+ :rtype: List[int]
6
+ """
7
+ l = sorted (arr )
8
+ dic , rank = {}, 0
9
+ pre_num = None
10
+ for i , num in enumerate (l ):
11
+ if pre_num != num :
12
+ rank += 1
13
+ dic [num ] = rank
14
+ pre_num = num
15
+
16
+ res = []
17
+ for num in arr :
18
+ res .append (dic [num ])
19
+ return res
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def removePalindromeSub (self , s ):
3
+ """
4
+ :type s: str
5
+ :rtype: int
6
+ """
7
+ if not s :
8
+ return 0
9
+ return 1 if s == s [::- 1 ] else 2
You can’t perform that action at this time.
0 commit comments