본문 바로가기

Algorithm/Implementation

(512)
(C++) - LeetCode (easy) 1422. Maximum Score After Splitting a String https://leetcode.com/problems/maximum-score-after-splitting-a-string/description/ 간단 전수조사 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 정답 변수 ms를 선언해 0으로 초기화해줍니다. 📔 풀이과정 1. s의 문자에 대해 loop를 수행하며 현재를 기준으로 왼쪽과 오른쪽 문자를 분리해 지역변수 a,b에 각각 저장합니다. 2. 문자열로부터 원하는 bit개수를 세 개수를 반환하는 countBit함수 문자 a,b에 대해서 수행합니다. 3. ms에 a의 0bit개수와 b의 1bit개수를 더한값과 비교해 최댓값을 저장합니다. 📔 정답 출력 | 반환 ms를 반환합니다. 📕 Code 📔 C++ class Solution { public: int c..
(C++) - LeetCode (easy) 1413. Minimum Value to Get Positive Step by Step Sum https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/description/ 구현 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 정답 value, 누적값 acc를 선언 후 각각 0으로 초기화합니다. 📔 풀이과정 nums의 원소에 대해 loop를 수행합니다. 1. acc에 현재값을 더합니다. 2. 현재 누적값이 1보다 작다면 value값을 1 - acc(조정이 필요한 구간까지의 합)값만큼 더해서 조정해줍니다. 이후 acc는 다시 1로 초기화됩니다. 3. nums의 값이 모두 양수라면 최소 start value인 1을 value에 저장합니다. 📔 정답 출력 | 반환 value를 반환합니다. 📕 Code 📔 C++ class ..
(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..