随笔分类 -  LeetCode刷题

遇到的经典LeetCode题目及解答
摘要:322. Coin Change class Solution { public: int coinChange(vector<int>& coins, int amount) { //动态规划 // 最优解法 // 算出1-11每个数的组成需要的最少硬币数 int nums[amount+1]; 阅读全文
posted @ 2020-09-13 21:13 cancantrbl 阅读(182) 评论(0) 推荐(0)
摘要:21. 合并两个有序链表 - Merge Two Sorted Lists 题目:https://leetcode.com/problems/merge-two-sorted-lists/ /** * Definition for singly-linked list. * struct ListN 阅读全文
posted @ 2020-09-13 11:46 cancantrbl 阅读(487) 评论(0) 推荐(0)
摘要:347. Top K Frequent Elements class Solution { public: vector<int> topKFrequent(vector<int>& nums, int k) { // hash map 储存frequency unordered_map<int, 阅读全文
posted @ 2020-09-12 22:00 cancantrbl 阅读(1164) 评论(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 阅读全文
posted @ 2020-09-12 13:27 cancantrbl 阅读(210) 评论(0) 推荐(0)
摘要:78. 子集 - Subsets 题目:https://leetcode.com/problems/subsets/ class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { vector<vector<int 阅读全文
posted @ 2020-09-11 21:36 cancantrbl 阅读(387) 评论(0) 推荐(0)
摘要:方法一:Insertion Sort 1 class MedianFinder { 2 vector<int> store; // resize-able 3 public: 4 /** initialize your data structure here. */ 5 MedianFinder() 阅读全文
posted @ 2020-09-11 17:26 cancantrbl 阅读(253) 评论(0) 推荐(0)