[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/easy/String] First The Difference
·
알고리즘/LeetCode
https://leetcode.com/problems/find-the-difference/ Find the Difference - 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 문자열 t는 문자열 s를 랜덤으로 섞어서 만들어지고 랜덤 위치에 문자를 하나 더 추가했다. 추가된 문자를 반환해라. char findTheDifference(string s, string t) { sort(s.begin(), s.end()); sort(t.begin(), t.end());..
[LeetCode/easy/String] First Unique Character in a String
·
알고리즘/LeetCode
https://leetcode.com/problems/first-unique-character-in-a-string/ First Unique Character in a String - 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가 주어졌을 때, s 내의 첫 번째 non-repeating 문자를 찾고 그것의 index 반환하기. 없으면 return -1 string의 find()함수는 find() 함수[#include algorithm]와 다른데, 이..
[LeetCode/easy/TwoPointer] Check If N and Its Double Exist
·
알고리즘/LeetCode
https://leetcode.com/problems/check-if-n-and-its-double-exist/ Check If N and Its Double Exist - 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 bool checkIfExist(vector arr) { for(int i=0; i
[LeetCode/easy/String] Merge Strings Alternately
·
알고리즘/LeetCode
https://leetcode.com/problems/merge-strings-alternately/ Merge Strings Alternately - 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 string mergeAlternately(string word1, string word2) { string answer = ""; int index = 0; while(1){ if(word2.size()
[LeetCode/easy/String] Reverse Prefix of Word
·
알고리즘/LeetCode
https://leetcode.com/problems/reverse-prefix-of-word/ Reverse Prefix of Word - 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 처음부터 ch가 있는 곳까지 reverse 하는 문제 만약 ch가 없다면 바로 word를 그대로 출력 string reversePrefix(string word, char ch) { size_t index = word.find(ch); if(index == string::npo..
녕이
'알고리즘' 카테고리의 글 목록 (14 Page)