전체 글
-
1338. Reduce Array Size to The Half릿코드(LEETCODE) 2020. 2. 11. 17:31
https://leetcode.com/problems/reduce-array-size-to-the-half 불러오는 중입니다... D 풀이 map 을사용하여 같은 요소의 가중치를 준다. 이후 vector 에 가중치값을 삽입하고 오름차순 정렬을 한다. 배열의 사이즈 절반 보다 가중치의 값이 크다면 가장 적은 숫자를 제거하여서 vector 의 크기를 절반으로 줄일수 있다. class Solution { public: int minSetSize(vector& arr) { const int size = arr.size(); map m; for (int i = 0; i < size; i++) { m[arr[i]]++; } const int half = size / 2; vector vi; for (const au..
-
263. Ugly Number릿코드(LEETCODE) 2020. 2. 10. 15:07
https://leetcode.com/problems/ugly-number/ Ugly 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 해당 문제는 2,3,5로 나누어지는 수를 구하는 문제입니다. 소수 판정하는 방법과 유사하지만 17 의 경우 소수이지만 2, 3, 5 나누어 떨어지지 않기 때문에 ugly number 입니다. 수 판정 3 3 -> 1 X 20 20 -> 10 -> 5 -> 1 X 6 6 -> 3 -> 1 X 4 4 -> 2 -> 1 ..
-
67. Add Binary릿코드(LEETCODE) 2020. 2. 10. 13:08
https://leetcode.com/problems/add-binary/ Add Binary - 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 틀린 풀이 문자열로 들어오는 해당 값을 십진수로 변경하고 덧셈을 한 결과를 다시 2진수로 변경하는 방법으로 풀이. 문제에서 문자열의 길이의 범위를 주어지지 않아 1차로 풀이하였다. INPUT으로 들어오는 문자열의 길이의 범이가 INT 유효 범위가 넘어서 오답이 됨. 문자열이 입력으로 들어오는 문제에서는 정수 유효 범위 ..
-
896. Monotonic Array릿코드(LEETCODE) 2020. 2. 10. 08:05
https://leetcode.com/problems/monotonic-array 불러오는 중입니다... 증가하거나, 감소하거나 인지 확인 하는 문제 키워드 - 단조함수 입력으로 들어오는 벡터의 개별 요소가 증가 하거나, 감소하는지를 판단하는 문제 벡터의 개별 요소 판정 1 2 3 4 5 6 7 8 9 증가함으로 O 9 8 7 6 4 3 2 1 감소함으로 O 4 5 6 4 8 9 2 1 4 5 6 4 증가하다가 감소한다 X Source class Solution { public: bool isMonotonic(vector& A) { bool inc = true; bool dec = true; for (int i = 0; i A[i+1]) inc =..
-
7. Reverse Integer - no solution릿코드(LEETCODE) 2020. 2. 9. 11:43
https://leetcode.com/problems/reverse-integer/ Reverse Integer - 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 signed int n 을 리버스 하는 문제다. reverse 했을때 int 유효범위가 넘어갈때 처리하는 방법이 키포인트인데 방법을 아직 못찾았다. 기록용으로 남겨 두자 나중에 풀자. INT 유효범위 체크를 안한 틀린 코드 #include class Solution { public: int revers..
-
190. Reverse Bits릿코드(LEETCODE) 2020. 2. 9. 00:45
https://leetcode.com/problems/reverse-bits/ Reverse Bits - 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 bit 를 좌우로 뒤집는 문제 입력 n 은 오른쪽 으로 쉬프트 하면서 마지막 에 비트가 있는지확인 sol 은 왼쪽으로 쉬프트하면서 or 연산 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t sol = 0; for(int i=0; i 1; ..