전체 글
-
1323. Maximum 69 Number릿코드(LEETCODE) 2020. 2. 3. 18:55
https://leetcode.com/problems/maximum-69-number/ Maximum 69 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 준어진 숫자에서 6, 9의 숫자를 변경 하여 가장 큰 값을 찾는 문제 완전탐색으로 숫자 원소 순서마다 9 를 대입 하고 가장 큰 값을 찾으 면 된다. class Solution { public: int maximum69Number(int num) { string s = to_string(num)..
-
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
-
decompress run length encoded list릿코드(LEETCODE) 2020. 2. 3. 16:18
https://leetcode.com/problems/decompress-run-length-encoded-list 불러오는 중입니다... 입력으로 들어오는 배열은 페어의 의미로 바라본다. RLE 알고리즘에 이해가 필요 한대 어렵지 않다. 2A3B4C 가 있다면 RLE 인코딩을 해제한다면 AABBBCCCC 가 된다. 최초의 코드는 아래와 같다. class Solution { public: vector decompressRLElist(vector& nums) { vector arr; for (int i = 0; i < nums.size(); i += 2) { int cand = nums[i]; int d = nums[i + 1]; for (int j = 0; j < cand; j++) { arr.push_..
-
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 =..
-
Codeforces Round #616 (Div. 2) - Codeforces Round #616 (Div. 2)코드포스(CodeForce) 2020. 2. 3. 15:25
http://codeforces.com/contest/1291/problem/B Problem - B - Codeforces codeforces.com 문제 strictly increasing or strictly decreasing array is sharpened 입력으로 들어오는 배열의 요소가 증가 하거나, 감소한다면 날카롭다고 한다. 또한 증가하다가 감소하는 ㅅ 모양도 날카롭다고 한다. 주어지는 N 개의 요소중 증가 or 감소 or 증가하다가 감소 한다면 날카롭운 배열이 된다. 제약 사항 같은 수가 연속으로 온다면 날카로운 배열이 아니다. 주어진 배열의 원소를 감소시킬 수 있다. #include #include #include #include #include #include #include #in..
-
Codeforces Round #616 (Div. 2) - A. Even But Not Even코드포스(CodeForce) 2020. 2. 3. 14:52
http://codeforces.com/contest/1291/problem/A Problem - A - Codeforces codeforces.com 문제 이해 주어진 문자열에 각 요소의 총합이 2로 나누어지고 원래 문자열의 2로 나누어지지 않는 수를 Even But Not Even이라고 한다. 즉 주어진 문자열(숫자)이 EBNE 가 인지 아닌지 판단한 하는 문제이다. 문자열에서 특정 요소를 제거하여 EBNE 인지 아닌지 판별하는 알고리즘을 구현 하면 된다. 제약 사항 입력으로 들어오는 N 의 값은 3000 이하이다. 전체의 합은 3000 이 넘지 않는다. 지울 수 있는 숫자 배열의 요소는 N-1이다. 접근법 이중 반복문을 통하여 N부터 N -1까지 계산한다고 가정하였을 때 N의 MAX는 3000 임으..