목록PS/LeetCode (15)
배움 저장소
https://leetcode.com/problems/sort-colors/ Sort Colors - 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. Selection Sort vector sortColors(vector& nums) { for(int i=0; i
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 1. 첫 시도 Set 사용방법을 기억할만해서 틀린풀이지만 기록해본다. Set 안에 Set을 하나 더 넣어서 시도했다. // input => vector& str; set bigSet; for(string &s:strs) { set smallSet; /* Set은 중복을 허용하지 않고, Set 값이 저장될 ..

https://leetcode.com/problems/rotate-image/ Rotate Image - 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. transpose I,J에 있는 값과 J,I에 있는 값을 바꾸어버리면 (1,1),(2,2)...(x,x)를 기준으로 대칭된 matrix를 얻는다. 2. 정렬 이제 행의 위치만 반대로 정렬해주면 처음 matrix의 90도 회전된 matrix를 얻을 수 있다. 방법은 두 가지가 있다. 1) Swap ..
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 1. Backtracking class Solution { public: vector subsets(vector& nums) { backtracking(nums, 0); return result; } private: vector result; vector saved; void backtracking(vector& nums, int..
https://leetcode.com/problems/unique-paths/ Unique Paths - 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. DFS풀이 ( 시간초과 ) class Solution { public: int uniquePaths(int m, int n) { result = 0; max_y = m-1; max_x = n-1; DFS(0,0); return result; } private: int result, max_y, max_x; ..
https://leetcode.com/problems/combination-sum/ Combination 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 1. Backtracking 사용 한 번 정리한 코드. 처음엔 Set을 사용했다. for문을 돌 때 현재 층(index)부터 시작하면 중복되는 경우의 수를 탐색하지 않아 Set을 사용할 필요가 없다. class Solution { public: vector combinationSum(vector& ca..

https://leetcode.com/problems/permutations/ Permutations - 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. BackTracking 참고자료 https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/ Backtracking을 사용하여 아래 그림을 구현해본다. DFS로 한 쪽 끝을 방문한 이후 다시 올라가서 다..
https://leetcode.com/problems/plus-one/ Plus One - 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 plusOne(vector& digits) { digits[digits.size()-1]++; for(int i= digits.size()-1; 0= 10) { digits[i] = digits[i] - 10; digits[i-1]++; } } if(digits[..