본문 바로가기

Algorithm/Implementation

(750)
(C++) - LeetCode (easy) 1403. Minimum Subsequence in Non-Increasing Order https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/description/ 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. 전체 원소의 합 totalSum과 부분 수열의 합 sum, 정답 vector ans를 선언 후 적절한 값을 넣어줍니다. accumulate 함수를 사용하면 쉽게 vector 내 원소 합을 구할 수 있습니다.2. nums를 내림차순으로 정렬합니다. 📔 풀이과정 내림차순으로 정렬된 nums의 좌측부터 loop를 돌면서 더하면 최소의 원소개수로 최대의 합을 구할 수 있습니다. 1. sum을 계속 더해가며 ans에 현재 원소를 push_back해줍니다. 2. sum은 포함된 원소들의 합, totalSu..
(C++) - LeetCode (easy) 1394. Find Lucky Integer in an Array https://leetcode.com/problems/find-lucky-integer-in-an-array/description/ Find Lucky Integer in an Array - LeetCode Can you solve this real interview question? Find Lucky Integer in an Array - Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value. Return the largest lucky integer in the array. If there is no l leetcode.com 간단 구현 문제였습니다..
(C++) - LeetCode (easy) 1374. Generate a String With Characters That Have Odd Counts https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/description/ Generate a String With Characters That Have Odd Counts - LeetCode Can you solve this real interview question? Generate a String With Characters That Have Odd Counts - Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times. The retu..
(C++) - LeetCode (easy) 1370. Increasing Decreasing String https://leetcode.com/problems/increasing-decreasing-string/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 구현문제였습니다. 📕 풀이방법 📔 입력 및 초기화 정답 변수 res, alphabat별 빈도수 freq를 선언 후 값을 구해 저장 해줍니다. 📔 풀이과정 res가 s길이보다 적은 동안 ..
(C++) - LeetCode (easy) 1365. How Many Numbers Are Smaller Than the Current Number https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 간단 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 정답 vector ans를 선언해줍니다. 📔 풀이과정 nums의 원소를 순회하며 자신..
(C++) - LeetCode (easy) 1360. Number of Days Between Two Dates https://leetcode.com/problems/number-of-days-between-two-dates/description/ LeetCode - The World's Leading Online Programming Learning Platform 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. -를 구분자로 연/월/일을 split하는 함수를 구현해 date1, date2에 각각 해당 함수 수행 후 yearMonth..
(C++) - LeetCode (easy) 1356. Sort Integers by The Number of 1 Bits https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 bitmasking을 이용한 문제였습니다. 📕 풀이방법 📔 풀이과정 1. arr을 정렬할 때 기준을 정해 sort해줍니다. 정렬 기준은 다음과 같습니다. 1 bit 개수..
(C++) - LeetCode (easy) 1351. Count Negative Numbers in a Sorted Matrix https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/description/ LeetCode - The World's Leading Online Programming Learning Platform 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. grid의 행 r, 열 c를 선언 후 값을 저장합니다.2. 정답변수 negatives를 선언 후 0..