목록PS/LeetCode (15)
배움 저장소
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