随笔分类 - LeetCode刷题
遇到的经典LeetCode题目及解答
发表于 2020-09-13 21:13阅读:161评论:0推荐:0
摘要:322. Coin Change class Solution { public: int coinChange(vector<int>& coins, int amount) { //动态规划 // 最优解法 // 算出1-11每个数的组成需要的最少硬币数 int nums[amount+1];
阅读全文 »
发表于 2020-09-13 11:46阅读:443评论:0推荐:0
摘要:21. 合并两个有序链表 - Merge Two Sorted Lists 题目:https://leetcode.com/problems/merge-two-sorted-lists/ /** * Definition for singly-linked list. * struct ListN
阅读全文 »
发表于 2020-09-12 22:00阅读:1110评论:0推荐:0
摘要:347. Top K Frequent Elements class Solution { public: vector<int> topKFrequent(vector<int>& nums, int k) { // hash map 储存frequency unordered_map<int,
阅读全文 »
发表于 2020-09-12 13:27阅读:186评论:0推荐:0
摘要:704. 二分查找 - Binary Search class Solution { public: int search(vector<int>& nums, int target) { int middle, left = 0; int right = nums.size()-1; while
阅读全文 »
发表于 2020-09-11 21:36阅读:324评论:0推荐:0
摘要:78. 子集 - Subsets 题目:https://leetcode.com/problems/subsets/ class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { vector<vector<int
阅读全文 »
发表于 2020-09-11 17:26阅读:214评论:0推荐:0
摘要:方法一:Insertion Sort 1 class MedianFinder { 2 vector<int> store; // resize-able 3 public: 4 /** initialize your data structure here. */ 5 MedianFinder()
阅读全文 »