320x100

코딩테스트 준비 66

78. Subsets

https://leetcode.com/problems/subsets/ Subsets - 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. Recursive (Backtracking) 흔히 트리에서 left node와 right node를 순차적으로 방문할 때 재귀적으로 방문하듯이 목록에서도 동일하게 방문한다. vector에서 push_ba..

141. Linked List Cycle

https://leetcode.com/problems/linked-list-cycle/ Linked List Cycle - 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 포인터로 연결된 목록이 주어졌을 때, 구성하는 목록이 순회하는지 여부를 반환하는 문제다. 스스로 풀기 [C++] /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(i..

스킬 체크 테스트 Level.3 - xx 회사의 2xN명의 사원들은

https://programmers.co.kr/skill_checks/304247 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 1차 - 케이스는 통과했지만 erase 때문에 효율성 통과 못함. #include #include using namespace std; int solution(vector A, vector B) { int answer = 0; sort(A.begin(), A.end(), greater()); sort(B.begin(), B.end(), greater()); for (int i=0; i min_diff) min_diff = *it..

83. Remove Duplicates from Sorted List

https://leetcode.com/problems/remove-duplicates-from-sorted-list/ Remove Duplicates from Sorted 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 Node의 목록이 주어졌을 때 중복값을 제거한 리스트를 반환하는 문제다. [C++] /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *..

88. Merge Sorted Array

https://leetcode.com/problems/merge-sorted-array/ Merge Sorted Array - 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개가 주어졌을 때, 0을 제외하고 두 목록을 합쳐 반환하는 문제다. [C++] class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n) { int count = 0; nums1.resize(m..

14. Longest Common Prefix

https://leetcode.com/problems/longest-common-prefix/ Longest Common Prefix - 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. 문자열 중 가장 짧은 길이를 찾는다. 2. 모든 문자열을 문자 순서대로 탐색한다. 3. 탐색하며 모든 문자열이 같으면 누적하고, 다르면 바로 리턴한다. 1. 모든 문자열을..

118. Pascal's Triangle

https://leetcode.com/problems/pascals-triangle/ Pascal's Triangle - 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 1 1 1 2 1 1 3 3 1 1 4 6 4 1 2는 윗 줄 2개의 1+1로, 3은 윗 줄 1+2, 2+1로, 4는 윗 ..

1. Two Sum

https://leetcode.com/problems/two-sum/ Two Sum - 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 정수 목록이 주어졌을 때, 목록 내 두 정수의 합이 목표 값이 되는 경우 그 목록의 인덱스를 반환하는 문제다. [C++] class Solution { public: vector twoSum(vector& nums, int target) { unordered_map cache; for (int i = 0; i < nums.size..

50. Pow(x, n)

https://leetcode.com/problems/powx-n/ Pow(x, n) - 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 실수d 와 제곱수n 를 받았을 때 pow(d,n)을 구하는 문제다. 단순히 d를 n번 곱셈하는게 제일 쉽겠지만, 그 안에서 반복되는 횟수를 줄여야 한다. 10번 처리할거 5번으로 줄이는 방식으로 2를 나누어 2배수로 처리한다. 더 큰 배수로 처리해도 되지만 예외처리가 그만큼 늘어날 수 있다. 제곱수n은 정수이므로 2로 나누었을 ..

49. Group Anagrams

https://leetcode.com/problems/group-anagrams/ Group Anagrams - 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 문자열의 목록이 주어졌을 때, Anagram(원본 문자를 한번 사용으로 재배열해 만든 문자)을 그룹화 해 반환하는 문제다. 주어진 문자열들을 각각 정렬하고 동일한 문자들끼리 모아둔다. (정렬된 문자열을 key로 unordered_map 사용) 그 후에 모아둔 문자열을 2중 벡터에 담아 반환한다. class..

320x100