leetcode
-
198. House Robber릿코드(LEETCODE) 2020. 2. 8. 14:34
https://leetcode.com/problems/house-robber/ House Robber - 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 { pu..
-
66. Plus One릿코드(LEETCODE) 2020. 2. 7. 17:52
https://leetcode.com/problems/plus-one 불러오는 중입니다... 입력으로 들어오는 배열에서 마지막 자리수에 1을 더한값을 출력 하는 문제. 마지막 글자가 9 인 경우 10이 됨으로 올림을 해줘야 한다. reverse 를 사용하여 배열의 요소를 반대로 돌리고 올림이 생기면 계속 추가 해주는 식으로 풀이 vector plusOne(vector& digits) { // 리버스를 사용하여 배열을 뒤집는다. reverse(digits.begin(), digits.end()); bool first = true; // 처음 1회 마지막 요소에 덧셈을 하기 위한 flag bool up = false; for (int i = 0; i < digits.size(); i++) { int cand..
-
290. Word Pattern릿코드(LEETCODE) 2020. 2. 7. 17:32
https://leetcode.com/problems/word-pattern/ Word Pattern - 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 pattern 의 문자열과 str 의 문자열이 pattern 을 이루는지 확인하는 문제 올바른 경우 pattern str 판정 abba cat dog dog cat O aba cat dog cat O aabb cat cat dog dog O 틀린 경우 pattern str 판정 abba dog dog dog do..
-
258. Add Digits릿코드(LEETCODE) 2020. 2. 7. 16:15
https://leetcode.com/problems/add-digits/ Add Digits - 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 38 -> 3 + 8 -> 11 -> 1 + 1 -> 2 주어진 숫자를 모두 더해서 한자리 숫자로 만드는 문제 n이 10 이하가 될 때까지 재귀 함수를 통해서 합산한 풀이는 아래와 같다. class Solution { public: int rec(int n) { if (n < 10) { return n; } int re..
-
1317. Convert Integer to the Sum of Two No-Zero Integers릿코드(LEETCODE) 2020. 2. 7. 15:04
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/ Convert Integer to the Sum of Two No-Zero Integers - 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 입력으로 들어오는 n의 값을 두 개의 Integer 합의 값을 찾는 문제로 정수에서는 0 이 포함되지 않아야 한다. n의 범위는 2
-
581. Shortest Unsorted Continuous Subarray릿코드(LEETCODE) 2020. 2. 5. 15:13
https://leetcode.com/problems/shortest-unsorted-continuous-subarray/ Shortest Unsorted Continuous Subarray - 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 문제 이해 입력으로 들어오는 배열에서 정렬되지 않은 구간을 찾는 문제 문제 접근 vector array를 하나를 추가 선언하고 정렬을 한다. 입력으로 들어온 nums array와 0부터 값이 다른 위치를 찾는다. 입력으로 들..
-
709. To Lower Case릿코드(LEETCODE) 2020. 2. 3. 19:02
https://leetcode.com/problems/to-lower-case/ To Lower Case - 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: string toLowerCase(string str) { for(int i=0;i= 65 && str.at(i)
-
1323. Maximum 69 Number릿코드(LEETCODE) 2020. 2. 3. 18:55
https://leetcode.com/problems/maximum-69-number/ Maximum 69 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 준어진 숫자에서 6, 9의 숫자를 변경 하여 가장 큰 값을 찾는 문제 완전탐색으로 숫자 원소 순서마다 9 를 대입 하고 가장 큰 값을 찾으 면 된다. class Solution { public: int maximum69Number(int num) { string s = to_string(num)..