반응형
https://leetcode.com/problems/decompress-run-length-encoded-list/
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의 원소를 순회하며 freq와 val을 저장해 freq만큼 val을 ans에 push_back해줍니다.
📔 정답 출력 | 반환
ans를 반환합니다.
📕 Code
📔 C++
class Solution {
public:
vector<int> decompressRLElist(vector<int>& nums) {
vector <int> ans;
for(int i = 0; i < nums.size() - 1; i+=2) {
int freq = nums[i];
int val = nums[i+1];
for(int j = 0; j < freq; j++) ans.push_back(val);
}
return ans;
}
};
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.