leetcode
behboyhiex
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
vector使用
vector<vector<int> > array(3);注意>和>之间的空格。array可以保存3个向量,向量的长度是可以改变的。array[i]返回的是第i个向量。同理,array[i][j]返回的是第i个向量中的第j个元素。使用array2[1].push_back(9)或者vector< vector<int> > array...原创 2018-03-27 11:13:07 · 197 阅读 · 0 评论 -
Leetcode179 Largest Number
Leetcode179 Largest Numberstruct compare { bool operator()(const string s1, const string s2) { return ((s1+s2) > (s2+s1)); } };class Solution {public: string largestNumber(vect...原创 2018-08-15 12:40:58 · 1307 阅读 · 0 评论 -
Leetcode 233 从1到n整数中1出现的次数
从1到n整数中1出现的次数Leetcode 233 剑指offer33class Solution {public: int countDigitOne(int n) { int ones = 0; for (long long m = 1; m <= n; m *= 10) ones += (n/m + 8) / 10 * m +...原创 2018-08-15 12:10:08 · 885 阅读 · 0 评论 -
LeetCode213 House Robber II
LeetCode213 House Robber II原型:LeetCode 198 House Robber首尾相连s1 抢0到n-2s2 抢1到n-1class Solution {public: int rob(vector<int>& nums) { int n=nums.size(); if(n==0) re...原创 2018-07-11 22:25:34 · 233 阅读 · 0 评论 -
LeetCode 198 House Robber
LeetCode 198 House Robber动态规划 beat100%memo[i]表示抢【i,n-1】最大收益memo[i]=max(memo[i],nums[j]+(j+2<n?memo[j+2]:0));class Solution {public: int rob(vector<int>& nums) { int n=nums.si...原创 2018-07-11 21:54:52 · 202 阅读 · 0 评论 -
Leetcode343 Integer Break
Leetcode343 Integer Break动态规划 beat100%memo[i]=max(j*(i-j),max(j*memo[i-j],memo[i]))class Solution {public: int integerBreak(int n) { if(n<1) return 0; vector<int> memo(n+...原创 2018-07-11 21:26:48 · 219 阅读 · 0 评论 -
leetcode 数组
832. Flipping an Image class Solution {public: vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) { vector<vector<int>> res =A; ...原创 2018-07-05 10:49:22 · 177 阅读 · 0 评论 -
Leetcode322 Coin Change
class Solution {public: int coinChange(vector<int>& coins, int amount) { if(amount < 0) return -1; vector<int> cnt(amount+1, amount+1); cnt[0] = 0; ...原创 2018-07-11 12:46:18 · 220 阅读 · 0 评论 -
Leetcode 300 最长递归子序列
Leetcode 300 最长递归子序列给定一个未排序的整数数组,找到最长的递增子序列的长度。例:输入:[10,9,2,5,3,7,101,18]输出: 4 说明:最长的子序列是[2,3,7,101],因此长度是4。class Solution {public: int lengthOfLIS(vector<int>& nums) { if (nu...原创 2018-06-20 15:04:51 · 665 阅读 · 0 评论 -
需要排序的最短子数组的长度
【题目】 给定一个无序数组arr,求出需要排序的最短子数组长度。 例如: arr = [1, 5, 3, 4, 2, 6, 7]返回4,因为只有[5, 3, 4, 2]需要排序。【思路】 双指针 第一次从左向右遍历,找左边比当前位置大的 第二次从右向左遍历,找右边比当前位置小的【代码】int findMinUnSortArray(int *arr ,...原创 2018-06-21 12:45:09 · 1142 阅读 · 0 评论 -
Leetcode 78. Subsets C++ beat100%
Leetcode 78. Subsets C++ beat100%Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [...原创 2018-05-12 16:02:26 · 821 阅读 · 1 评论 -
LeetCode11. Container With Most Water
LeetCode11. Container With Most Water求水池蓄水最大面积思路:维护一个变量max_pool 记录最大,双指针左右,哪边小 乘以r-l与max_pool比较,更新max_pool 哪边小移动哪边 beat 98.3class Solution {public: int maxArea(vector<int>& h...原创 2018-09-05 19:15:58 · 204 阅读 · 0 评论
分享