Stack3 Leetcode 1614. Maximum Nesting Depth of the Parentheses 참고: leetcode r0bertz 1 2 3 4 5 6 7 8 9 class Solution: def maxDepth(self, s: str) -> int: ans=cnt=0 for i in s: if i =="(" : cnt+=1 ans=max(ans,cnt) elif i==")" : cnt-=1 return ans cs 2021. 8. 31. Leetcode 682. Baseball Game 1 2 3 4 5 6 7 8 9 class Solution: def calPoints(self, ops: List[str]) -> int: tmp=[] for i in ops: if i=='C': tmp.pop() elif i=='D':tmp.append (tmp[-1]*2) elif i=="+":tmp.append(tmp[-1]+tmp[-2]) else : tmp.append(int(i)) return (sum(tmp)) cs 2021. 8. 30. Leetcode 1441 Build an Array with Stack Operations 1 2 3 4 5 6 7 8 9 10 11 class Solution: def buildArray(self, target: List[int], n: int) -> List[str]: myn=max(target) tmp= [i+1 for i in range(myn)] ans=[] for i in tmp: if i in target: ans.append("Push") else: ans.append("Push") ans.append("Pop") return ans Colored by Color Scripter cs n으로 만들어진 List를 바탕으로 target을 만들어야하는데 문제에서 언급한 Push, Pop 으로 만들면되는데 주의할것이 target의 가장 큰 값을 for문의 range에 넣으면됩니다 2021. 8. 30. 이전 1 다음