[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..
[LeetCode/easy/TwoPointer] Find First Palindromic String in the Array
·
알고리즘/LeetCode
https://leetcode.com/problems/find-first-palindromic-string-in-the-array/ Find First Palindromic String in the 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 for문으로도 할 수 있고, Two Pointer로 양 옆에서 포인터를 가리키며 진행할 수도 있다. 이번에는 two pointer로 해봤다. string firstPalindrome(vector words)..
[LeetCode/easy/Array] Single Number
·
알고리즘/LeetCode
https://leetcode.com/problems/single-number/ Single 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 int singleNumber(vector& nums) { for(int i=0; i
[LeetCode/easy/Array] Best Time to Buy and Sell Stock
·
알고리즘/LeetCode
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 배열을 쭉 훑는 for문을 지나면서 minn을 구하는데 만약 minn보다 작은 게 나오면 해당 원소 다음의 sub array 내에서 max 값을 찾는다. 그 후, minn을 업데이트하고 answer 에 더 큰 값을 넣어준다 (sell-minn와 ..
[LeetCode/easy/Array] Pascal's triangle II
·
알고리즘/LeetCode
https://leetcode.com/problems/pascals-triangle-ii/ Pascal's Triangle 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 vector getRow(int rowIndex) { vector ans(rowIndex+1); ans[0].push_back(1); for(int i=1; i
녕이
'Easy' 태그의 글 목록 (2 Page)