Blognawa
시작페이지로 | 검색공급자추가

뜨는 UCC 동영상더보기

t
t
t
>> "쿠케캬캬 개발 기록" 님의 인기글 리스트 rss 최신글
1. LeetCode 409. Longest Palindrome ( 쿠케캬캬 개발 기록 List | 24-06-08 13:33 )

https://leetcode.com/problems/longest-palindrome/ 짝수 개의 문자는 모두 palindrome으로 만들 수 있고, 1개의 문자는 가운데에 넣을 수 있습니다. class Solution { public: int longestPalindrome(string s) { int cnt['z' + 1] = {0}; for(char c : ... Tag: Algorithm, leetcode

2. LeetCode 2486. Append Characters to String to Make Subsequence ( 쿠케캬캬 개발 기록 List | 24-06-08 14:00 )

https://leetcode.com/problems/append-characters-to-string-to-make​-subsequence 투포인터를 이용하여 풀었습니다 s를 순회하면서 s[i] == t[j]라면 j의 포인터를 올려줍니다. j까지 이동한 t의 prefix는 s의 subsequence로 활용할 수 있었으므로, t.size() - ... Tag: Algorithm, leetcode

3. LeetCode 3110. Score of a String ( 쿠케캬캬 개발 기록 List | 24-06-08 14:09 )

https://leetcode.com/problems/score-of-a-string 인접한 두 수의 아스키코드 값 차이를 모두 더해주면 됩니다. class Solution { public: int scoreOfString(string s) { int score = 0; for(int i=1; i<s.size(); i++) { score += abs(s[i] -... Tag: Algorithm, leetcode

4. LeetCode 260. Single Number III ( 쿠케캬캬 개발 기록 List | 24-06-08 14:59 )

https://leetcode.com/problems/single-number-iii nums의 모든 수를 xor해서 a ^ b를 구해줍니다. a ^ b의 특정 비트가 1로 켜져있다면, a와 b의 해당 비트는 다릅니다. 해당 비트를 기준 삼아 두 그룹으로 분기하여 nums를 xor 해줍니다. 각 그룹에 대해 a와 b가 도출됩니다. cl... Tag: Algorithm, leetcode

5. LeetCode 1002. Find Common Characters ( 쿠케캬캬 개발 기록 List | 24-06-08 15:15 )

https://leetcode.com/problems/find-common-characters 먼저 words[0]의 각 문자 개수를 구해줍니다. 이어서, 남은 words를 순회하며 각 문자 개수를 구해주고, words[0]에 나타났던 문자 개수 만큼만 기억해줍니다. class Solution { public: vector<string> commonCh... Tag: Algorithm, leetcode

6. LeetCode 136. Single Number ( 쿠케캬캬 개발 기록 List | 24-06-08 15:18 )

https://leetcode.com/problems/single-number/ 모든 수를 xor 연산해주면, single number만 남게 됩니다. class Solution { public: int singleNumber(vector<int>\& nums) { int res = 0; for(int num : nums) res ^= num; return res; } ... Tag: Algorithm, leetcode

7. LeetCode 1442. Count Triplets That Can Form Two Arrays of Equal XOR ( 쿠케캬캬 개발 기록 List | 24-06-09 17:50 )

https://leetcode.com/problems/count-triplets-that-can-form-two-ar​rays-of-equal-xor arr의 prefix xor을 초기화해주면, prefixXor[j] ^ prefixXor[i]로 arr[i] ~ arr[j - 1]의 xor된 연산을 즉시 구할 수 있습니다. O(N^3)의 시간으로 풀 수 있었습니다. (... Tag: Algorithm, leetcode

8. LeetCode 1608. Special Array With X Elements Greater Than or Equal X ( 쿠케캬캬 개발 기록 List | 24-06-09 18:44 )

https://leetcode.com/problems/special-array-with-x-elements-great​er-than-or-equal-x/ nums를 정렬하고, nums를 순회하며 x 가능 여부를 검사해줍니다. 각 인덱스에서 lower bound를 수행하면, 인덱스보다 크거나 같은 요소의 개수를 구할 수 있습니다. class Solutio... Tag: Algorithm, leetcode

9. LeetCode 846. Hand of Straights ( 쿠케캬캬 개발 기록 List | 24-06-12 21:33 )

https://leetcode.com/problems/hand-of-straights 트리맵에 각 카드의 개수를 저장해줍니다. 트리의 첫번째 요소(가장 작은 값)를 꺼내고, groupSize만큼 연이은 카드가 남아있는지 검사해줍니다. 다 사용된 카드는 제거하고, 트리맵에서 제거해줍니다. class Solution { public: b... Tag: Algorithm, leetcode

10. LeetCode 1122. Relative Sort Array ( 쿠케캬캬 개발 기록 List | 24-06-12 21:34 )

https://leetcode.com/problems/relative-sort-array arr2 각 요소의 인덱스를 기억해주고, 이 정보를 이용하여 arr1을 정렬해줍니다. class Solution { public: vector<int> relativeSortArray(vector<int>\& arr1, vector<int>\& arr2) { vector<int> i... Tag: Algorithm, leetcode

11. LeetCode 979. Distribute Coins in Binary Tree ( 쿠케캬캬 개발 기록 List | 24-05-18 14:11 )

https://leetcode.com/problems/distribute-coins-in-binary-tree dfs로 풀었습니다. 각 노드가 받아야하는 코인은 음수, 줘야하는 코인은 양수로 반환이 됩니다. 좌측 노드, 우측 노드, 자신이 줘야하는 코인의 합이 이동해야하는 코인의 개수가 됩니다. class Solution { public:... Tag: Algorithm, leetcode

12. LeetCode 1325. Delete Leaves With a Given Value ( 쿠케캬캬 개발 기록 List | 24-05-18 15:00 )

https://leetcode.com/problems/delete-leaves-with-a-given-value 재귀적으로 풀 수 있었습니다. 각 노드가 leaf node이고 val == target이라면 NULL을 반환하고, 상위 노드는 해당 값으로 업데이트합니다. class Solution { public: TreeNode* removeLeafNodes(T... Tag: Algorithm, leetcode

13. LeetCode 2331. Evaluate Boolean Binary Tree ( 쿠케캬캬 개발 기록 List | 24-05-18 15:09 )

https://leetcode.com/problems/evaluate-boolean-binary-tree 좌우측 하위 노드가 true 또는 false 라면, 노드의 val에 따라 and 또는 or 연산을 수행하여 결과를 반환해줍니다. class Solution { public: bool evaluateTree(TreeNode* root) { if(root->val... Tag: Algorithm, leetcode

14. LeetCode 2000. Reverse Prefix of Word ( 쿠케캬캬 개발 기록 List | 24-05-01 13:55 )

https://leetcode.com/problems/reverse-prefix-of-word ch의 index를 찾아준 뒤 뒤집어줍니다. class Solution { public: string reversePrefix(string word, char ch) { int idx = find(word, ch); if(idx == -1) return word; for(int i=0; ... Tag: Algorithm, leetcode

15. LeetCode 2441. Largest Positive Integer That Exists With Its Negative ( 쿠케캬캬 개발 기록 List | 24-05-03 23:13 )

https://leetcode.com/problems/largest-positive-integer-that-exist​s-with-its-negative 각 수의 절댓값에 대해 특정 부호에 대한 값이 나왔는지 기억해주고, 다른 부호 값이 또 나오는지 확인해줍니다. class Solution { public: int findMaxK(vector<int>\& nu... Tag: Algorithm, leetcode

<<이전10 <이전   1 | 2   다음 다음10>>
t