[LeetCode/easy/Simulation] Add Digits
·
알고리즘/LeetCode
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 숫자가 일의 자리일 때까지 각 자릿수를 더하는 문제 문자열을 사용해서 쉽게 더하는 방식으로 진행했다. int addDigits(int num) { string s = to_string(num); int n = 0; if(s.size() == 1) return num; do{ n = 0; for(int i=0; i 1);..
[LeetCode/easy/BinarySearch] Valid Perfect Square
·
알고리즘/LeetCode
https://leetcode.com/problems/valid-perfect-square/ Valid Perfect Square - 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 sqrt 함수를 사용하지 않고 num이 제곱근이라면 true 반환하기 bool isPerfectSquare(int num) { int s = 1, e = num; while(s
[LeetCode/easy/BinarySearch] Intersection of Two Arrays II
·
알고리즘/LeetCode
https://leetcode.com/problems/intersection-of-two-arrays-ii/ Intersection of Two Arrays II - 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 정수 배열 nums1, num2가 주어지고 교집합 배열을 반환해라. 결과의 각 요소는 두 배열에 표시된 횟수만큼 나타나야 하며, 원하는 순서로 결과를 반환할 수 있습니다. Intersection of Two Arrays 문제에서는 예제 1) nums1 ..
[LeetCode/easy/BinarySearch] First Bad Version
·
알고리즘/LeetCode
https://leetcode.com/problems/first-bad-version/ First Bad Version - 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 각 버전은 이전 버전에 기반해서 디벨롭되고 bad 버전 이후의 모든 버전은 모두 bad 하다. n개의 버전이 주어지고 첫 번째 bad 버전을 찾고 싶다. 버전이 bad 했는지 아닌지 반환하는 API bool isBadVersion(version)이 주어지고 최소로 이 API를 호출해야 한다. i..
[LeetCode/easy/BinarySearch] Sort(x)
·
알고리즘/LeetCode
https://leetcode.com/problems/sqrtx/ Sqrt(x) - 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 pow함수를 사용하지 않고 sqrt 기능 구현하기 int mySqrt(int x) { long n = 1; while(n*n
[LeetCode/easy/TwoPointer] Reverse String II
·
알고리즘/LeetCode
https://leetcode.com/problems/reverse-string-ii/ Reverse String II - 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 문자열 s와 정수 k가 주어진다. - 문자열의 시작부터 매 2k 문자마다 첫 번째 k자를 반전시킵니다. - 만약 남은 문자가 k보다 적다면, 그들 전체를 reverse - 만약 2k보단 적지만 k보다 크거나 같다면, 첫 번째 k 문자를 reverse 하고 나머지는 내버려둔다. abcdefg ->..
[LeetCode/easy/TwoPointer] Assign Cookies
·
알고리즘/LeetCode
https://leetcode.com/problems/assign-cookies/ Assign Cookies - 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 멋진 부모라고 가정하고 아이들에게 쿠키를 나눠준다고 해보자. 그러나 자녀 당 꼭 하나만 줘야 한다. 각 자식(i)은 g [i]: 아이들이 만족할 쿠키의 최소 사이즈 각 쿠키(j)의 사이즈 s[j] 만약 쿠키 사이즈가 아이들의 g [i]보다 크다면, 자식 i에게 쿠키 j를 줄 수 있다. 당신의 목표는 만족하..
[LeetCode/easy/TwoPointer] Intersection of Two Arrays
·
알고리즘/LeetCode
https://leetcode.com/problems/intersection-of-two-arrays/ Intersection of Two Arrays - 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개 주어지고, 교집합 구하기 → 동일한 값이면 하나로 취급 ex) num1 = [4,9,5], num2 = [9,4,9,8,4] -> [9,4] or [4,9] vector intersection(vector nums1, vector nums2) { ..
[LeetCode/easy/String] Is Subsequence
·
알고리즘/LeetCode
https://leetcode.com/problems/is-subsequence/ Is Subsequence - 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 만약 s가 t의 subsequence라면 true 여기서 subsequence란, 원본 문자열에서 몇 개의 문자를 지웠더니 생성된 새로운 문자열이다. bool isSubsequence(string s, string t) { int index = 0; for(int i=0; i
녕이
'알고리즘/LeetCode' 카테고리의 글 목록