[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
[LeetCode/easy] Isomorphic Strings
·
알고리즘/LeetCode
https://leetcode.com/problems/isomorphic-strings/ Isomorphic Strings - 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 paper title 01023 01023 이와 같이 알파벳의 위치와 개수가 동일한지 아닌지 체크하면 된다. 나는 위의 예제처럼 숫자를 넣어줬다. 각 인덱스를 보고 이전에 있던 거면 그때 그 숫자를 넣어주고 새로운 거면 +1 한 값을 넣어줬다. 그런데 여기서 문제는 바로 "abcdefghij..
[LeetCode/easy] Valid Palindrome
·
알고리즘/LeetCode
https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - 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 isPalindrome(string s) { bool answer = true; string st; for(int i=0; i= 'a' && s[i] = 'A' && s[i]
[LeetCode/easy] Add Binary
·
알고리즘/LeetCode
https://leetcode.com/problems/add-binary/submissions/ Add Binary - 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 정수끼리 더하는 방법을 생각하다가 그냥 컴퓨터 시스템 시간에 배웠던 연산 방법을 생각했다. c라는 변수를 두고 올림수가 생기면 이를 여기에 넣어주고 같이 연산해주는 것이다. 1. 더 짧은 문자열을 동일한 길이로 만들어준다. 앞에 0 붙여주기 2-1) (1, 1)의 경우, 결괏값은 0인데 c의 값을 ..
[LeetCode/easy] Length of Last Word
·
알고리즘/LeetCode
https://leetcode.com/problems/length-of-last-word/ Length of Last 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 stringstream과 getline으로 문자열을 구분자로 구분해서 하려고 했는데, ex2에서 구분자 " "로는 안되길래 그냥 뒤에서부터 단어의 길이를 세줬다. int lengthOfLastWord(string s) { int answer = 0; for(int i=s.size()-1;..
[LeetCode/easy] strStr()
·
알고리즘/LeetCode
https://leetcode.com/problems/implement-strstr/ Implement strStr() - 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 문자열 1에 문자열 2가 포함되어있다면 어디서부터 시작하는지를 묻는 문제, string::npos를 사용하면 된다. int strStr(string haystack, string needle) { int answer = 0; size_t nPos = haystack.find(needle); if..
[LeetCode/easy] Valid Parentheses
·
알고리즘/LeetCode
https://leetcode.com/problems/valid-parentheses/ Valid Parentheses - 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 STL Stack을 사용하면 쉽게 풀리는~ 문제~ class Solution { public: bool isValid(string s) { stack st; for(int i=0; i
[LeetCode/easy] Longest Common Prefix
·
알고리즘/LeetCode
https://leetcode.com/problems/longest-common-prefix/submissions/ Longest Common Prefix - 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 #include #include #include #include using namespace std; string longestCommonPrefix(vector strs){ string answer = ""; for(int i=0; i
[LeetCode/easy] Roman To Integer
·
알고리즘/LeetCode
https://leetcode.com/problems/roman-to-integer/ Roman to Integer - 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 #include #include #include #include using namespace std; int checkString(char a){ switch (a){ case 'I': return 1; case 'V': return 5; case 'X': return 10; case 'L': re..
녕이
'알고리즘/LeetCode' 카테고리의 글 목록 (4 Page)