[LeetCode/easy/Array] Remove Duplicates from Sorted Array
·
알고리즘/LeetCode
https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Remove Duplicates from Sorted 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 감소하지 않는 순서로 정렬된 nums 배열이 주어진다. 각 유니크한 요소들이 오직 한 번만 나타나도록 중복을 삭제해라. input array를 수정하는 방식으로 해야됨. 중복 수를 제거하고나서 몇 개가 나오는지 출력해라. STL v..
[프로그래머스/Lv2] 124 나라의 숫자
·
알고리즘/프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/12899 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 이 문제는 LeetCode easy 문제에서 풀었던 것과 비슷하다. 처음에는 백트래킹으로 해서 쭉 올라가는 완전 탐색으로 할까 했는데 제한사항이 n ≤ 500,000,000 이하이길래 절대 안되겠구나..^^ 무조건 수학이겠군... 싶었다. 보면 알 수 있지만 수가 반복된다. 1, 2, 4 이러면 아주.. 예전에 풀었던 요일 구하는 문제처럼 1, 2, 4 배열을 만들고 이를 인덱스로 접근해서 풀 수..
[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
[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의 값을 ..
녕이
'알고리즘' 카테고리의 글 목록 (16 Page)