* Computer Science/Algorithm 83

739. Daily Temperatures

문제: https://leetcode.com/problems/daily-temperatures/ Daily Temperatures - 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 현재 날짜의 기온보다 높은 기온이 나오는 날짜의 차를 각각 구하는 문제다. class Solution { public: vector dailyTemperatures(vector& temperatures) { int n = temperatures.size(); vector ans(n, ..

1368. Minimum Cost to Make at Least One Valid Path in a Grid

https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/ Minimum Cost to Make at Least One Valid Path in a Grid - 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 class Solution { public: vector directions = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int dp[101..

1202. Smallest String With Swaps

https://leetcode.com/problems/smallest-string-with-swaps/ Smallest String With Swaps - 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 문자열에서 주어진 pair에 들어있는 index들을 스왑하는데, 해당 경우의 수 중 lexiographically하게 가장 작은 문자열을 구하는 문제다. class Solution { public: vector indices; string indiceStr; ve..

1711. Count Good Meals

문제: https://leetcode.com/problems/count-good-meals/ Count Good Meals - 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 deliciousness의 값 중 두 개를 더했을 때 2의 n승의 값이 되는지 판별하는 문제다. class Solution { public: int countPairs(vector& deliciousness) { int mod = 1000000000 + 7; vector twosPower; ..

1752. Check if Array Is Sorted and Rotated

문제: https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/ Check if Array Is Sorted and Rotated - 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 정렬된 배열이 rotate되어있으면 true, 그렇지 않다면 false를 출력하는 문제다. 정렬이 되어있으면 nums[i] nums[(i + 1) % n]){ cnt++; } } return cnt > 1 ? false ..

983. Minimum Cost For Tickets - DP

문제: https://leetcode.com/problems/minimum-cost-for-tickets/ Minimum Cost For Tickets - 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 주어진 days에 train 여행을 할 수 있는 티켓을 사는 경우 중 가장 작은 가격의 합을 구하는 문제다. 중요 포인트는 1일, 7일, 30일에 대한 티켓이 있고 이를 days에 있는 날들을 사용해서 푸는 것이다. 흠... class Solution { publ..

abbreviation

1. Generalized Abbreviation 문제: https://leetcode.com/problems/generalized-abbreviation/ Account Login - 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 string이 주어질때 길이만큼 숫자로 줄이는 문제다. 예를 들면, "abcdefg"가 있을 때 a는 길이가 1이므로 "1bcdefg"로 줄일 수 있다. 다만 숫자가 연속되면 안되는 제약이 있다. class Solution { pub..

41. First Missing Positive

문제: https://leetcode.com/problems/first-missing-positive/ First Missing Positive - 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 1,2,3~으로 positive number가 구성되어있는데, 주어진 배열에서 빠진 positive number 중 가장 작은 값을 linear time & constant space만에 구하는 문제다. 예를 들어보면, {1, 2, 3, 5, 6}이 주어지면 1부터 시작..