自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(19)
  • 收藏
  • 关注

原创 Leetcode 914. 卡牌分组

方法一:暴力class Solution {public: bool hasGroupsSizeX(vector<int>& deck) { int N = deck.size(); unordered_map<int,int> ans; for(int i = 0;i < N;++i) ...

2020-03-27 17:06:58 148

原创 Leetcode 999车的可用捕获量

代码(c++):class Solution {public: int numRookCaptures(vector<vector<char>>& board) { int cnt = 0,xm = 0,yf = 0; int dx[4] = {-1,1,0,0}; int dy[4] = {0,0,-1,...

2020-03-26 22:37:25 165

原创 Leetcode 892. 三维形体的表面积

算法代码(C++):class Solution {public://理解为一个二维数组,输入:[[1,2],[3,4]]//0,0位置放一个;0,1位置放2个;1,0位置放3个;1,1位置放4个 int surfaceArea(vector<vector<int>>& grid) { //减法思想,所有立方体的面(立方体个数*6)-...

2020-03-25 14:26:39 161

原创 leetcode 面试题 17.16. 按摩师

代码(c++)://动态规划class Solution {public: int massage(vector<int>& nums) { int n = int(nums.size()); if(n == 0) return 0; if(n == 1) return nums[0]; vect...

2020-03-24 11:07:15 132

原创 Leetcode876. 链表的中间结点

算法(C++):/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: L...

2020-03-23 17:02:20 112

原创 Leetcode945. 使数组唯一的最小增量

代码(C++):class Solution {public: int minIncrementForUnique(vector<int>& A) { sort(A.begin(),A.end()); int ans = 0; for(int i = 1;i < A.size();++i){ ...

2020-03-22 10:54:10 97

转载 Leetcode 面试题40. 最小的k个数

class Solution {public: vector<int> getLeastNumbers(vector<int>& arr, int k) { vector<int> vec(k,0); if(k == 0) return vec; priority_queue<int&gt...

2020-03-20 16:12:20 84

原创 Leetcode 409. 最长回文串

class Solution {public: int longestPalindrome(string s) { unordered_map<char,int> cnt; int rst = 0; bool flag = false; for(char c : s) ++cnt[c];...

2020-03-19 14:40:05 107

原创 Leetcode 836. 矩形重叠

代码实现(C++):class Solution {public: bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) { if(rec1[0] >= rec2[2] || rec1[2] <= rec2[0] || rec1[3] <= r...

2020-03-18 09:33:27 83

转载 Leetcode 1160. 拼写单词

代码实现(C++):class Solution {public: int countCharacters(vector<string>& words, string chars) { unordered_map<char,int> chars_cnt; int cnt = 0; for(char c : ...

2020-03-17 13:12:14 178

原创 Leetcode 面试题 01.06. 字符串压缩

代码实现(C++):class Solution {public: string compressString(string S) { if(S.length() == 0) return S; string rst = ""; int cnt = 1; char ch = S[0]; for(int i ...

2020-03-16 11:57:21 99

原创 Leetcode 695 岛屿的最大面积

代码实现(C++):class Solution {public://深度优先遍历 int dfs(vector<vector<int>> &grid,int i,int j){ if(i>= 0 && i<grid.size() && j>=0 && j<grid...

2020-03-15 16:02:59 181

转载 Leetcode 300. 最长上升子序列

代码实现(C++): 动态规划class Solution {public: int lengthOfLIS(vector<int>& nums) { int n = (int)nums.size(); if(n == 0) return 0; vector<int> dp(n,0);//n个元素,初值...

2020-03-14 11:06:58 91

转载 Leetcode 169. 多数元素

代码(C++):class Solution {public://哈希表 int majorityElement(vector<int>& nums) { unordered_map<int,int> counts;//key是int型,value为int型 int majority = 0,cnt = 0; ...

2020-03-13 16:02:18 88

转载 Leetcode 1071. 字符串的最大公因子

题目:对于字符串 S 和 T,只有在 S = T + … + T(T 与自身连接 1 次或多次)时,我们才认定 “T 能除尽 S”。返回最长字符串 X,要求满足 X 能除尽 str1 且 X 能除尽 str2。示例 1:输入:str1 = “ABCABC”, str2 = “ABC”输出:“ABC”示例 2:输入:str1 = “ABABAB”, str2 = “ABAB”输出:“...

2020-03-12 20:46:23 90

转载 Leetcode 1013. 将数组分成和相等的三个部分

代码实现(C++):class Solution {public: bool canThreePartsEqualSum(vector<int>& A) { int s = accumulate(A.begin(), A.end(), 0); if (s % 3 != 0) { return false; ...

2020-03-11 12:48:23 104

原创 Leetcode 543. 二叉树的直径

题目描述:给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过根结点。示例 :给定二叉树 1 / \ 2 3 / \ 4 5 返回 3, 它的长度是路径 [4,2,1,3] 或者 [5,2,1,3]。注意:两结点之间的路径长度是以它们之间边的数目表示。算法思想:如...

2020-03-10 17:57:43 190

原创 Leetcode 121. 买卖股票的最佳时机

第一种思路 暴力法基本思想:两层循环。第一天买入,从后一天依次卖出,取最大值。然后第二天买入,从后一天依次卖出,更新最大值。代码实现(C++):class Solution {public: int maxProfit(vector<int>& prices) { int n = prices.size(),maxprofit = 0; f...

2020-03-09 15:05:14 115

原创 c++ vector容器

向量(Vector)是一个能够存放 任意类型 的 动态数组 。Vector 的size函数返回vector大小,返回值类型为"Member type size_type is an unsigned integral type",即无符号整数。...

2020-03-09 14:38:09 95

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除