stack 7

1190. Reverse Substrings Between Each Pair of Parentheses

https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/ Reverse Substrings Between Each Pair of Parentheses - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 부분 부분 서브스트링이 소괄호로 감싸져있는데, 가장 안쪽 스트링 부터 reverse 시키면서 소괄호를 벗기는 문제 계산하기 편하도록 쪼갠 뒤, stack을 이용해서 넣으며, ..

algorithm 2020.10.25

921. Minimum Add to Make Parentheses Valid

leetcode.com/problems/minimum-add-to-make-parentheses-valid/ Minimum Add to Make Parentheses Valid - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ())(() 와 같이 parentheses가 주어졌을 때, valid하게 만들기 위해서 몇 개를 추가해야 하는가? 구하는 문제, medium 으로 되어 있지만 easy 수준으로 정말 간단하다. 32ms class Solution: def ..

algorithm 2020.10.20

496. Next Greater Element I

leetcode.com/problems/next-greater-element-i/ Next Greater Element I - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 이 문제도 전형적인 스택문제 문제 설명이 명확하지 않아서 헷갈리는 부분이 있을 수 있는데 결국 num2 기준으로 각 숫자 다음에 오는 큰 숫자를 찾아놓고 num1에 각각 매핑되는 큰 숫자를 담아 리턴하는 문제다. class Solution: def nextGreaterElement(self,..

algorithm 2020.10.20

735. Asteroid Collision

https://leetcode.com/problems/asteroid-collision/ Asteroid Collision - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 스택 문제를 더 연습하고 싶어서 하나 더 골라봤다. 고려해야할 경우의 수를 잘 나눠놓고 접근해야 무한루프에 빠지지 않는다. 스택을 이용하되, 연쇄작용 하는 부분을 신경써야함. 40% class Solution: def asteroidCollision(self, asteroids: List[i..

algorithm 2020.10.18

316. Remove Duplicate Letters [R]

https://leetcode.com/problems/remove-duplicate-letters/ Remove Duplicate Letters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 항상 자신이 없는 스택 문제를 오랜만에 풀어봤다. 결국 제한 시간 안에 못풀었다. 대충 250케이스중 200몇개만 통과하고 예외 케이스가 발생. 코드를 딱 봐도 ... 복잡. class Solution: def removeDuplicateLetters(self, s: s..

algorithm 2020.10.18