본문 바로가기

leetcode48

8] Leetcode 1313. Decompress Run-Length Encoded List Decompress Run-Length Encoded List - 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 decompressRLElist(vector& nums) { vectorans; for(int i = 0; i 2020. 6. 21.
7] Leetcode 1365. How Many Numbers Are Smaller Than the Current Number 숫자로 이뤄진 벡터내에 각 벡터값보다 작은 값의 갯수를 반환하는 문제. How Many Numbers Are Smaller Than the Current Number - 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문을 통해 해결했다. class Solution { public: vector smallerNumbersThanCurrent(vector& nums) { vectorans; int cnt = 0; for(int i=0; i 2020. 6. 21.
6] Leetcode 771. Jewels and Stones Jewels and Stones - 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 numJewelsInStones(string J, string S) { int ans = 0; for(int i = 0;i 2020. 6. 21.
5] Leetcode 1342. Number of Steps to Reduce a Number to Zero Number of Steps to Reduce a Number 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 주어진 숫자를 짝수면 반으로 나누고, 홀수면 -1해서 0으로 만드는데 걸리는 연산 횟수를 반환하는 문제다. class Solution { public: int numberOfSteps (int num) { int ans = 0; while(num !=0){ if(num %2 == 0){ num /=2; ans++; } else{ num-.. 2020. 6. 21.