[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/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..
[LeetCode/easy] Ransom Note
·
알고리즘/LeetCode
https://leetcode.com/problems/ransom-note/ Ransom Note - 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 alpha 배열을 통해서 해당 알파벳 개수를 세고 magazine에서 해당 알파벳 개수를 감소시킨다. 만약 0보다 큰 게 있다면 ransomNote에 아직 알파벳이 남았는데 magazine이 끝난 것이므로 return false bool canConstruct(string ransomNote, string magaz..
[LeetCode/easy] Reverse Vowels of a String
·
알고리즘/LeetCode
https://leetcode.com/problems/reverse-vowels-of-a-string/ Reverse Vowels of 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 투 포인터를 사용해서 앞 뒤로 l, r 포인터를 두고 - 둘 다 모음인 경우 swap, l++, r-- - 둘 다 자음인 경우 l++, r-- - 왼쪽만 자음 l++ - 오른쪽만 자음 r-- bool isVowel(char c){ if(c == 'a' || c =..
[LeetCode/easy] Word Pattern
·
알고리즘/LeetCode
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과 v의 단어를 짝지어준다. (a-dog, b-cat) 이런 식으로. 1. 문자열 s을 공백 없이 단어들만 v에 넣어주기 (getline, sstream) 2. 문자열 v와 pattern의 길이 다르면 바로 return false 3. checkS()를 통해 현재 문자열 v와 다른 패턴이랑 짝지어진 ..
[LeetCode/easy] Valid Anagram
·
알고리즘/LeetCode
https://leetcode.com/problems/valid-anagram/ Valid Anagram - 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 alpha 배열을 통해서 알파벳 순서에 맞춰서 개수를 세웠다. 애너그램은 알파벳의 개수와 종류만 같으면 된다! bool isAnagram(string s, string t) { bool answer = true; int alphas[26]; int alphat[26]; for(int i=0; i
녕이
'string' 태그의 글 목록