标签:mic inf span seq end class image lse append
题目描述:
方法一:pythonO(N)O(1)
class Solution: def maxDepthAfterSplit(self, seq: str) -> List[int]: d = 0 ans = [] for s in seq: if s == "(": d += 1 ans.append(d%2) else: ans.append(d%2) d -= 1 return ans
方法二:找规律:python版
class Solution: def maxDepthAfterSplit(self, seq: str) -> List[int]: ans = [] for i,s in enumerate(seq): if s == "(": ans.append(i%2) else: ans.append(1-i%2) return ans
java版
class Solution { public int[] maxDepthAfterSplit(String seq) { int [] ans = new int [seq.length()]; int idx = 0; for(char s:seq.toCharArray()){ ans[idx++] = s == ‘(‘? idx%2:(1-idx%2); } return ans; } }
标签:mic inf span seq end class image lse append
原文地址:https://www.cnblogs.com/oldby/p/12611651.html