LeetCode 739. Daily Temperatures
·
Algorithm/문제풀이
Daily Temperatures - LeetCodeCan you solve this real interview question? Daily Temperatures - Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmerleetcode.com문제 설명기온을 나타내는 temperatures 배열이 주어졌을때 현재 날짜의 온도보다 더 따듯한 기온을 얻기위해 기다리는 수를 answer 배열을 반환하시오만약에 현자 날짜의 온도보..
[알고리즘] 단조 스택 (Monotonic Stack)
·
Algorithm/알고리즘
1. 단조 스택스택 내부의 원소들이 일정한 증가 OR 감소 순서를 유지하도록 관리하는 자료구조 활용 기법. 스택은 가장 마지막에 들어온 원소가 가장 먼저 나간다.단조 스택 역시 일반적인 스택을 사용하지만 새로운 원소를 삽입할 때 스택의 TOP과 비교하여 조건에 맞지 않는 원소를 제거함. 단조 증가 스택 & 단조 감소 스택스택의 원소들이 증가 혹은 감소하는 구조의 스택 증가 스택 => 주로 처음 등장하는 더 작은 원소를 찾는데 활용.감소 스택 => 주로 처음 등장하는 더 큰 원소를 찾는데 활용.while (!st.empty() && st.top() > cur) => 단조 증가 스택//ORwhile (!st.empty() && st.top() 단조 감소 스택{ st.pop();}st.push(cur)..
LeetCode 140. Word Break II
·
Algorithm/문제풀이
Word Break II - LeetCodeCan you solve this real interview question? Word Break II - Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order. Note thaleetcode.com 문제 설명문자열 s와 단어 목록 wordDict가 주어진다.wordDict에 존재하는 단어들을 사용하여 문자열 s 전체를 나눌 수 있는 모든 경우의 문장을 반환하는 문제이다.단어 사이에는 ..
LeetCode 73. Set Matrix Zeroes
·
Algorithm/문제풀이
Set Matrix Zeroes - LeetCodeCan you solve this real interview question? Set Matrix Zeroes - Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's. You must do it in place [https://en.wikipedia.org/wiki/In-place_algorithm]. Example 1: [httpsleetcode.com 문제 설명m x n 크기의 정수 행렬 matrix가 주어진다.행렬의 원소 중 0이 존재할 경우, 해당 원소가 속한 행과 열의 모든 원소를 0으로 변경해야 한다. 추가 도전- O(mn)..
LeetCode 4. Median of Two Sorted Arrays
·
Algorithm/문제풀이
Median of Two Sorted Arrays - LeetCodeCan you solve this real interview question? Median of Two Sorted Arrays - Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1leetcode.com문제 설명크기가 m인 정렬된 배열 nums1 , 크기가 n인 정렬된 배열 nums2가 주어질 때 두 배열을 합쳤을 때 정렬된 배열의 중앙값을 반환하라실행시간 복잡도는 ..
LeetCode 33. Search in Rotated Sorted Array
·
Algorithm/문제풀이
Search in Rotated Sorted Array - LeetCodeCan you solve this real interview question? Search in Rotated Sorted Array - There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly left rotated at an unknown index k (1 leetcode.com 문제 설명nums배열은 원래 오름차순으로 정렬된 배열에서 왼쪽으로 k번 회전한 배열이다예를 들러 nums가 [4,5,6,7,0,1,2] 로 주어지면원래 배열인 [0..