-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweeklyContest28.py
53 lines (48 loc) · 1.36 KB
/
weeklyContest28.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
class Solution():
def checkRecord(self, s):
"""
:type s: str
:rtype: bool
"""
return s.count("A") < 2 and "LLL" not in s
def optimalDivision(self, nums):
"""
:type nums: List[int]
:rtype: str
"""
n = len(nums)
if n == 0:
return ""
if n == 1:
return str(nums[0])
if n == 2:
return str(nums[0]) + "/" + str(nums[1])
else:
return str(nums[0]) + "/(" + "/".join(str(i) for i in nums[1:]) + ")"
def splitLoopedString(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
n = len(strs)
for i in range(n):
s = strs[i]
if s < s[::-1]:
strs[i] = s[::-1]
js = "".join(strs)
maxc = max(js)
opts = []
for i in range(n):
s = strs[i]
if maxc not in s:
continue
ls = len(s)
for j in range(ls):
if s[j] == maxc:
opt1 = s[j:] + "".join(strs[i+1:]) + "".join(strs[:i]) + s[:j]
opt2 = s[j::-1] + "".join(strs[i+1:]) + "".join(strs[:i]) + s[:j:-1]
opts.append(opt1)
opts.append(opt2)
return max(opts)