본문 바로가기

전체 글310

35★] Leetcode 1299. Replace Elements with Greatest Element on Right Side Replace Elements with Greatest Element on Right Side - 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 for문 두 번 돌려도 되지만 시간 초과. 대신 뒤에서부터 최댓값을 계산하면서 vector에는 앞에서부터 값을 추가해주면 된다. class Solution { public: vector replaceElements(vector& arr) { vectorans; int max = 0; ans.insert(ans.begin.. 2020. 7. 19.
34] Leetcode 1351. Count Negative Numbers in a Sorted Matrix Count Negative Numbers in a Sorted Matrix - 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 grid.size() vs grid[0].size() class Solution { public: int countNegatives(vector& grid) { int ans=0; for(int i = 0;i 2020. 7. 19.
33] Leetcode 1304. Find N Unique Integers Sum up to Zero Find N Unique Integers Sum up to Zero - 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 sumZero(int n) { vectorans; if(n%2 == 0){ for(int i = 1;i 2020. 7. 15.
32] Leetcode 807. Max Increase to Keep City Skyline https://leetcode.com/problems/max-increase-to-keep-city-skyline/ Max Increase to Keep City Skyline - 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 각 행과 열의 최댓값을 구하고 최대 increase할 수 있는 높이는 두 최댓값 중 작은 값이므로 두 값중 작은 값에서 기존 값을 더한 값들을 리턴한다. class Solution { public: int maxIncreaseKeeping.. 2020. 7. 12.
31] Leetcode 1512. Number of Good Pairs https://leetcode.com/problems/number-of-good-pairs/ Number of Good Pairs - 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: int numIdenticalPairs(vector& nums) { int ans = 0; for(int i = 0;i 2020. 7. 12.
30★★] Leetcode 1010. Pairs of Songs With Total Durations Divisible by 60 Pairs of Songs With Total Durations Divisible by 60 - 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 #시간초과주의 for문 2번 돌리면 시간초과난다. 앞에 더해서 나머지가 0이 되는 숫자 갯수만큼 pair의 갯수가 늘어난다. class Solution { public: int numPairsDivisibleBy60(vector& time) { int vis[60] = {0}; int ans = 0; for(int i =.. 2020. 7. 10.