목록PS (34)
배움 저장소
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ Find First and Last Position of Element in 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 Solution 1: 반복문의 조건문에서 target값을 찾은 코드 class Solution { public: vector searchRange(vector&..
https://leetcode.com/problems/jump-game/submissions/ Jump Game - 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: bool canJump(vector& nums) { saved_nums = nums; count = sav..
첫 풀이. 벡터안에 값을 저장하고 투포인터로 비교한다. #include #include class Solution { public: bool isPalindrome(int x) { if(x
class Solution { public: int reverse(int x) { bool isMinus = false; if(x==INT_MIN) { return 0; } else if(x INT_MAX/10) return 0; reversed = reversed*10 + x%10; x /= 10; } return isMinus? reversed*-1 : reversed; } };
class Solution { public: string convert(string s, int numRows) { if(numRows==1) return s; int divider = numRows + numRows-2; vector matrix(numRows); for(int i=0; i
leetcode.com/problems/add-two-numbers/submissions/ Add Two Numbers - 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 처음에 int형에다가 값을 저장했다가 다시 ListNode를 만들어 반환했다. 그러면 INT_MAX를 넘어서는 값이 나와서 long long 타입으로 바꾸어주었는데 그래도 long long max 를 넘는 값이 나와서 ListNode로 바로 변환해주는 방식으로 바꾸었다. 이 때 buffer를 만..
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 처음 iterator를 썼다가, Edge Case를 해결하지 못했다. {3,3} 일때 0,0이 나왔음. #include #include using namespace std; class solution{ vector twoSum(vector& nums, int target) { map m; for(int i=0; i

programmers.co.kr/learn/courses/30/lessons/42897 코딩테스트 연습 - 도둑질 도둑이 어느 마을을 털 계획을 하고 있습니다. 이 마을의 모든 집들은 아래 그림과 같이 동그랗게 배치되어 있습니다. 각 집들은 서로 인접한 집들과 방범장치가 연결되어 있기 때문에 인접한 programmers.co.kr i번째 집을 방문하면 i-1번째 집을 방문할 수 없고 i-2번째 집을 방문할 수 있다. i번째 집을 방문하지 않으면, i-1번째 집을 방문할 수 있다. 배열을 만들어, 도둑이 집을 방문하며 얻은 최대값을 저장하면된다. 이때 i번째 집은 방문 하거나 방문 하지 않거나 선택할 수 있다. 최대값을 반환하면 되므로 다음과 같은 식을 세울 수 있다. i번째 최적값은 (i-2번째 최적값 ..