-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1003.检查替换后的词是否有效.py
49 lines (44 loc) · 1.1 KB
/
1003.检查替换后的词是否有效.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
#
# @lc app=leetcode.cn id=1003 lang=python
#
# [1003] 检查替换后的词是否有效
#
# @lc code=start
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
if self.check(s,0) == len(s):
return True
else:
return False
def check(self,s,point):
if s[point] != "a":
return -1
point += 1
if point >= len(s):
return -1
if s[point] == "a":
point = self.check(s,point)
if point == -1:
return -1
if point >= len(s) or s[point] != "b":
return -1
point += 1
if point >= len(s):
return -1
if s[point] == "a":
point = self.check(s,point)
if point == -1:
return -1
if point >= len(s) or s[point] != "c":
return -1
point += 1
if point < len(s) and s[point] == "a":
point = self.check(s,point)
if point == -1:
return -1
return point
# @lc code=end