본문 바로가기

전체 글103

[leetcode] 155.Min Stack https://leetcode.com/problems/min-stack/description/ Min Stack - LeetCode Can you solve this real interview question? Min Stack - Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: * MinStack() initializes the stack object. * void push(int val) pushes t leetcode.com 문제 이해 MinStack을 디자인 Stack과 모든게 동일하지만 getMin()을 호출 시 st.. 2023. 8. 26.
[leetcode] 856.Score of Parentheses(Retry) https://leetcode.com/problems/score-of-parentheses/description/ Score of Parentheses - LeetCode Can you solve this real interview question? Score of Parentheses - Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: * "()" has score 1. * AB has score A + B, w leetcode.com 설명 String s 를 매개변수로 받고, socre를 반.. 2023. 8. 20.
[leetcode] 682.Baseball Game https://leetcode.com/problems/baseball-game/description/ Baseball Game - LeetCode Can you solve this real interview question? Baseball Game - You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record. You are given a list of strings operations, where operations[i] is leetcode.com Stack을 이용 정직하게 설명되어있는 대로 구현만 하면 되는 문제 pop과 push.. 2023. 8. 19.
[leetcode] Valid Parentheses(유효한 괄호) https://leetcode.com/problems/valid-parentheses/description/ Valid Parentheses - LeetCode Can you solve this real interview question? Valid Parentheses - Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the sam leetcode.com 조건 1. 여는괄호는 반드시 같은 타입의 괄호로 닫혀야한다 2. 여는.. 2023. 8. 16.
[프로그래머스] 올바른 괄호 https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제이해 - '('과 ')'으로 구성된 문자열이 주어짐 - '()'이 한 쌍으로 존재해야 올바른 괄호 -> ex) '()', '(())()' 가능 - 문자열이 올바르면 true, 틀리면 false를 반환 해결방법 - Stack함수 사용 - '('이 들어온다면 push - ')'이 들어온다면 - isEmpty를 이용 stack이 비어있는지 검사 - if 비어있다면 return false - 아니라면.. 2023. 8. 14.
[프로그래머스] 점프와 순간 이동 https://school.programmers.co.kr/learn/courses/30/lessons/12980 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 설명 거리를 이동하는 아이언 슈트, 이동시에 배터리를 소모한다. 이동하고자 하는 거리가 주어졌을 때 최소한의 배터리를 소모하여 이동하는 방법을 찾기. 점프: 한번에 K칸을 점프하여 이동 워프: 현재까지 이동한거리 x 2 만큼 이동 점프 시 배터리를 소모하지만 워프 시 배터리를 소모하지 않는다. 방법 주어진 목표 거리를 역순으로 나누어 파악 2로 나누다가(워프) 나누어지지 않는다면 거리에(점프필요).. 2023. 8. 12.