942. DI String Match
—Easy
https://leetcode.com/problems/di-string-match/
class Solution: def diStringMatch(self, S: str) : N = len(S) list_ans = [] start = 0 end = N for elt in S: if elt == "I": list_ans.append(start) start += 1 if elt == "D": list_ans.append(end) end -= 1 list_ans.append(end) return list_ans # s = Solution() # print(s.diStringMatch("IDID"))
思路:
1.题目意思第一时间没看明白,注意S与A所代表的即可