自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Leetcode股票问题分析(Most consistent ways of dealing with the series of stock problems)

在leetcode上所有的股票问题有:1,121. Best Time to Buy and Sell Stock2,122. Best Time to Buy and Sell Stock II3,123. Best Time to Buy and Sell Stock III4,188. Best Time to Buy and Sell Stock IV5,309. Best Ti...

2020-01-11 07:05:32 375

原创 Leetcode345

345 Reverse Vowels of a StringWrite a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: “hello”Output: “holle”Example 2:Input: “leetcode”Output: “le...

2019-10-02 13:45:05 243

原创 剑指offer10_斐波那契数列

题目描述大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。斐波那契数列的定义如下:f(0) = 0;f(1) = 1;f(n) = f(n - 1) + f(n - 2); n >= 2解法一:#include <iostream>using namespace std;class Solution{p...

2019-04-02 09:31:46 177

原创 剑指offer07_重建二叉树

题目:输入某二叉树的前序遍历和中序遍历的结果,请重建该二叉树(假设没有重复数字)。树节点定义如下:struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) :val(x), left(nullptr), right(nullptr) {}};解题思路:1.前序遍...

2019-03-26 21:07:54 123

原创 剑指offer04_二维数组中的查找

题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下的递增的顺序排序,请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数思路:从最右上角或者最左下角开始遍历Solution:#include <iostream>#include <vector>using namespace std;class Sol...

2019-03-24 20:55:41 100

原创 剑指offer06_从尾到头打印链表

题目:从尾到头打印链表思路:1,注意传入函数的是指向链表头的指针,在函数中不应该直接使用这个指针,而是应该用一个指针的临时变量来遍历链表2,方法一:使用栈来实现3,方法二:递归在本质上就是一个栈结构,所以也可以用递归来实现Solution:#include <iostream>#include <stack>#include <vector>...

2019-03-24 20:18:36 117

原创 剑指offer05_替换空格

题目:请实现一个函数,把字符串中的每个空格替换成“%20”,例如,输入”We are happy.”,则输出”We%20are%20happy.”。解题思路:本题主要考察对字符串的处理一般像这种需要向后扩充容量重新整理内存的,最好能够考虑到从尾部开始整理的方法1.指针都可以当作数组使用,但是指针本身不检查是否超出数组范围。2.对字符串的处理都应该考虑最后的空字符’\0’。3.应该一个...

2019-03-18 21:00:24 82

原创 Leetcode438

Find All Anagrams(字母异位词) in a String:Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of b...

2019-03-02 16:36:08 276

原创 Leetcode344

Reverse String:Write a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by modifying the in...

2019-02-27 19:47:30 212

原创 leetcode125

Valid Palindrome:Given a string, determine if it is a palindrome(回文), considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as val...

2019-02-26 20:12:12 242

原创 Leetcode215

Kth Largest Element in an Array:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,...

2019-02-23 18:04:21 100

原创 快速排序:

代码:#include &lt;vector&gt;#include &lt;iostream&gt;using namespace std;class quickSort{private: void quicksort(vector&lt;int&gt;&amp; nums, int l, int r){ if( l &lt; r ){ ...

2019-02-23 16:50:27 111

原创 Leetcode88

Merge Sorted Array:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.Y...

2019-02-23 12:05:07 207

原创 Leetcode80

Remove Duplicates from Sorted Array II:Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for...

2019-02-04 00:28:27 236

原创 Leetcode27

Remove Element:Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying...

2019-01-22 20:22:24 149

原创 Leetcode26

Remove Duplicates from Sorted Array:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for anothe...

2019-01-17 19:51:08 197

原创 Leetcode435

Non-overlapping Intervals:Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note:You may assume the interval...

2019-01-10 20:34:51 206

原创 Leetcode455

Assign Cookies:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minim...

2019-01-10 11:18:00 222

原创 Leetcode300

Longest Increasing Subsequence:Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increas...

2019-01-07 20:36:13 378

原创 Leetcode416

Partition Equal Subset Sum:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Not...

2019-01-05 16:30:41 128

原创 01背包问题

最原始的01背包问题:Solution01: 自顶向下,记忆化搜索class Knapsack01{private: vector&lt;vector&lt;int&gt;&gt; memo; int bestValue(const vector&lt;int&gt; &amp;w, const vector&lt;int&gt; &amp;v, int index, in...

2019-01-03 20:44:42 182

原创 Leetcode198

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...

2019-01-02 19:04:24 126

原创 Leetcode343

Integer Break:Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input:...

2018-12-17 21:03:39 196

原创 Leetcode70

Climbing Stairs:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n wil...

2018-12-10 19:59:21 95

原创 Leetcode51

N-Queens:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzl...

2018-12-06 20:28:44 281

原创 Leetcode200

Number of Islands:Given a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertica...

2018-12-04 20:34:23 265

原创 Leetcode79

Word Search:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or ...

2018-12-03 20:52:03 247

原创 Leetcode77

Combinations:Given two integers n and k, return all possible combinations of k numbers out of 1 … n.Example:Input: n = 4, k = 2Output:[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]Solution:#incl...

2018-11-28 17:11:48 168

原创 Leetcode46

PermutationsGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]Solution:#include &lt;...

2018-11-27 19:19:59 111

原创 Leetcode17

Letter Combinations of a Phone Number:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just...

2018-11-25 17:34:04 114

原创 Leetcode235

Lowest Common Ancestor of a Binary Search TreeSolution:#include &lt;iostream&gt;using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) ...

2018-11-22 19:34:36 272

原创 Leetcode437

Path Sum III:You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf...

2018-11-20 20:23:47 267

原创 Leetcode257

Solution:#include &lt;iostream&gt;#include &lt;vector&gt;using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), r...

2018-11-19 20:37:44 170

原创 Leetcode112

Path Sum:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node with no children....

2018-11-15 19:16:24 293

原创 Leetcode226

Invert Binary Tree:Invert a binary tree.Example:Solution:#include &lt;iostream&gt;using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int...

2018-11-13 20:05:41 220

原创 Leetcode104

Maximum Depth of Binary Tree:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A le...

2018-11-12 20:18:15 61

原创 Leetcode347

Top K Frequent Elements:Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Outpu...

2018-11-07 21:03:02 170

原创 Leetcode279

Perfect Squares:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12Output: 3Explanation: 12 = 4 + 4 + ...

2018-11-05 21:14:07 346

原创 Leetcode102

Binary Tree Level Order Traversal:Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).Solution:#include &lt;iostream&gt;#include &l...

2018-10-29 19:37:07 77

原创 Leetcode145:

Binary Tree Postorder Traversal:Given a binary tree, return the postorder traversal of its nodes’ values.Example:Input: [1,null,2,3]Output: [3,2,1]Solution:#include &lt;iostream&gt;#include &lt...

2018-10-25 20:06:16 197

空空如也

空空如也

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

TA关注的人

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