일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 715. Range Module
- Python Code
- iterator
- 프로그래머스
- Regular Expression
- Protocol
- 315. Count of Smaller Numbers After Self
- 시바견
- 운영체제
- t1
- LeetCode
- concurrency
- shiba
- 109. Convert Sorted List to Binary Search Tree
- Class
- Python Implementation
- Python
- attribute
- 30. Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- data science
- Generator
- 밴픽
- kaggle
- DWG
- 파이썬
- 컴퓨터의 구조
- Decorator
- 43. Multiply Strings
- Today
- Total
목록Computer Science/C++ (38)
Scribbling
https://leetcode.com/problems/product-of-array-except-self/ class Solution { public: vector productExceptSelf(vector& nums) { vector zero_idx; int zero_cnt = 0; vector dp1(nums.size()); vector dp2(nums.size()); int prod = 1; for (int i = 0; i < nums.size(); i++) { int num = nums[i]; if (num == 0) { zero_idx.push_back(i); zero_cnt++; } else { prod *= num; dp1[i] = prod; } } prod = 1; for (int i =..
LeetCode 347. Top K Frequent Elements https://leetcode.com/problems/top-k-frequent-elements/ Top K Frequent Elements - LeetCode Can you solve this real interview question? Top K Frequent Elements - Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] leetcode.com stru..
class Solution { public: vector groupAnagrams(vector& strs) { unordered_map map; for (string str : strs) { string sorted_str = str; sort(sorted_str.begin(), sorted_str.end()); map[sorted_str].push_back(str); } vector ret; for (auto e : map) { ret.push_back(e.second); } return ret; } };
https://leetcode.com/problems/valid-anagram/ class Solution { public: bool isAnagram(string s, string t) { if (s.size() != t.size()) { return false; } unordered_map map1; unordered_map map2; for (auto c : s) { map1[c]++; } for (auto c : t) { map2[c]++; } for (auto x : map1) { if (x.second != map2[x.first]) { return false; } } return true; } };
https://leetcode.com/problems/contains-duplicate/ class Solution { public: bool containsDuplicate(vector& nums) { return nums.size() > unordered_set(nums.begin(), nums.end()).size(); } };
#include #include class Solution { public: vector threeSum(vector& nums) { using namespace std; sort(nums.begin(), nums.end()); vector ret; for (size_t i=0; i 0 and nums[i] == nums[i-1]) { continue; } size_t j = i + 1, k = nums.size() - 1; while (j < k) { int num1 = nums.at(i), num2 = nums.at(j), num3 = nums.at(k); int summed = num1 + num2 + num3; if (summed == 0) { vector temp = {num1, num2, nu..
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* curPtr = new ListNode(0); ListNode* ret = curPtr; int sum=0, carry =..
#include #include using namespace std; class Solution { public: vector twoSum(vector& nums, int target) { vector res; unordered_map hash; for (int i = 0; i < nums.size(); i++) { int num = target - nums[i]; // found if (hash.find(num) != hash.end()) { res.push_back(hash[num]); res.push_back(i); return res; } hash[nums[i]] = i; } return res; } }; int main() { vector vec{ 2, 7, 11, 15 }; Solution()..