본문 바로가기

Algorithm/자료구조

(106)
(C++) - LeetCode (easy) 1507. Reformat Date https://leetcode.com/problems/reformat-date/description/ map을 사용해본 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. 한 문자열을 공백을 구분자로 잘라 vector 으로 반환하는 split 함수를 구현합니다. stringstream을 사용하면 됩니다.2. split된 문자열을 dateInfo에 저장합니다. key는 변환할 문자, value에는 변환될 문자를 저장할 monthMap, dayMap를 선언 후 맞는 형태로 저장합니다. 11th, 12th 외 숫자 1의 자리가 1또는 2라면 st, nd를 붙여야 됨에 주의합니다. 📔 풀이과정 split 된 dateInfo의 day, month, year에 해당하는 부분을 지역변수를 선언해 저장합니다. 📔 정답..
(C++) - LeetCode (easy) 1408. String Matching in an Array https://leetcode.com/problems/string-matching-in-an-array/description/ set 과 문자열 검색 함수 find를 사용해본 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 set s와 vector ans를 선언해줍니다. 📔 풀이과정 1. 자기 자신이 아닌 문자열을 서로 비교해 부분 문자열이라면 해당 값을 s에 insert해줍니다. 2. s의 원소들을 ans에 push_back해줍니다. 📔 정답 출력 | 반환 ans를 반환합니다. 📕 Code 📔 C++ class Solution { public: vector stringMatching(vector& words) { set s; vector ans; for(int i = 0; i < words.size();..
(C++) - LeetCode (easy) 1389. Create Target Array in the Given Order https://leetcode.com/problems/create-target-array-in-the-given-order/description/ Create Target Array in the Given Order - LeetCode Can you solve this real interview question? Create Target Array in the Given Order - Given two arrays of integers nums and index. Your task is to create target array under the following rules: * Initially target array is empty. * From left to right read n leetcode.c..
(C++) - LeetCode (easy) 1331. Rank Transform of an Array https://leetcode.com/problems/rank-transform-of-an-array/description/ LeetCode - The World's Leading Online Programming Learning Platform 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. 더 큰 원소가 queue front에 오도록 priority_queue pq를 선언 후 arr의 원소를 삽입합..
(C++) - LeetCode (easy) 1299. Replace Elements with Greatest Element on Right Side https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 priority_queue와 map을 이용해 해결한 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. 정답 vector ans, 내림차순으로..
(C++) - LeetCode (easy) 1290. Convert Binary Number in a Linked List to Integer https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 자료구조 linked list를 이용한 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. 정답 변수 decimal을 선언 후 0으로 초기화해줍니다..
(C++) - LeetCode (easy) 1287. Element Appearing More Than 25% In Sorted Array https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/description/ Element Appearing More Than 25% In Sorted Array - LeetCode Can you solve this real interview question? Element Appearing More Than 25% In Sorted Array - Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer..
(C++) - LeetCode (easy) 1128. Number of Equivalent Domino Pairs https://leetcode.com/problems/number-of-equivalent-domino-pairs/description/ Number of Equivalent Domino Pairs - LeetCode Can you solve this real interview question? Number of Equivalent Domino Pairs - Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can leetcode.com 자료구조를 ..