leetcode
-
Split a String in Balanced Strings릿코드(LEETCODE) 2020. 2. 3. 18:42
https://leetcode.com/problems/split-a-string-in-balanced-strings 불러오는 중입니다... 스택을 이용하여 문자열에 페어를 맞춰주는 문제 RLRRLLRLRL 문자열이 주어 질때 표로 그리면 아래와 같을 수 있다. 문자열 TOP DESCRIPTION R EMPTY 스택에 아무것도 없으니 삽입 RL R 스택에 탑이 임으로 POP 한다. COUNT 증가 RLR EMPTY 스택에 아무것도 없으니 삽입 RLRL R 스택에 탑이 임으로 POP 한다. COUNT 증가 RLRLR EMPTY 스택에 아무것도 없으니 삽입 RLRLRR R 이전 스택이 같으므로 삽입 RLRLRRL R 스택이 탑이 R 임으로 POP 스택이 비어있는지 확인 하고 COUNT 증가 RLRLRRLL R..
-
subtract the product and sum of digits of an integer submissions릿코드(LEETCODE) 2020. 2. 3. 17:13
https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer 불러오는 중입니다... 주어지는 숫자를 분해하여 분해한 수의 합과, 곱셈의 차를 출력 하는 문제 class Solution { public: int subtractProductAndSum(int n) { vector arr; while (n) { int cand = n % 10; n /= 10; arr.push_back(cand); } const int count = arr.size(); int mul = 1; for (int i = 0; i < count; i++) mul = mul * arr[i]; int add = 0; for (int i = 0; i ..
-
find numbers with even number of digits릿코드(LEETCODE) 2020. 2. 3. 16:55
https://leetcode.com/problems/find-numbers-with-even-number-of-digits 불러오는 중입니다... 주어진 숫자에의 자릿수가 짝수인지 판별하는 문제 class Solution { public: int getCnt(int cand) { int count = 0; while(cand) { cand /= 10; count++; } return count; } int findNumbers(vector& nums) { const int size = nums.size(); int sol = 0; for(int i=0; i
-
defanging-an-ip-address릿코드(LEETCODE) 2020. 2. 3. 16:02
https://leetcode.com/problems/defanging-an-ip-address/ Defanging an IP Address - 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: string defangIPaddr(string address) { string s; for (int i = 0; i < address.size(); i++) { char ch =..