
leetcode
文章平均质量分 69
想做程序媛的小太阳
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode 53:最大子序和
原题描述:给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。示例:输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。解答:1. 暴力搜索---时间复杂度O(n^3),空间复杂度O(1) 这个解答是超过本题要求的复杂度的,所以并不能ACclass Solution...原创 2018-04-22 10:21:42 · 201 阅读 · 0 评论 -
树和堆知识点总结
一、 树1. 树的定义树(英语:Tree)是一种无向图(undirected graph),其中任意两个顶点间存在唯一一条路径。或者说,只要没有回路的连通图就是树。二叉树(英语:Binary tree)是每个节点最多只有两个分支(不存在分支度大于2的节点)的树结构。通常分支被称作“左子树”和“右子树”。二叉树的分支具有左右次序,不能颠倒。完全二叉树:叶节点只能出现在最下层和次下层,...原创 2018-09-01 10:21:09 · 442 阅读 · 0 评论 -
Leetcode 198:House Robber
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...原创 2018-08-13 12:58:54 · 184 阅读 · 0 评论 -
Leetcode 70: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 will be a positive...原创 2018-08-14 17:10:05 · 143 阅读 · 0 评论 -
二叉树的遍历
很很很久没刷leetcode,又开始了要找不到工作的焦虑感,从今天开始,重拾刷题更博客的生活!二叉树的遍历老生常谈,面试也经常出现,从方法上讲分为递归方法和非递归方法,从类型上讲分为前序中序和后序,还有层序等等。1. 二叉树的前序遍历(Leetcode 144)a. 递归方法/** * Definition for a binary tree node. * public c...原创 2018-07-28 15:37:39 · 234 阅读 · 0 评论 -
Leetcode 128:Longest Consecutive Sequence
TBA原创 2018-05-05 21:56:07 · 135 阅读 · 0 评论 -
Leetcode 155: Min Stack
Description:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top()...原创 2018-05-04 15:23:52 · 139 阅读 · 0 评论 -
[To review] Leetcode 394: Decode String
Description:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note tha...原创 2018-04-24 20:41:53 · 154 阅读 · 0 评论 -
Leetcode 152:乘积最大子序列
原题描述:找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。例如, 给定序列 [2,3,-2,4],其中乘积最大的子序列为 [2,3] 其乘积为 6。解答:1. 暴力搜索---O(n^2) 没有AC:超时class Solution { public int maxProduct(int[] nums) { int n = nums.length; ...原创 2018-04-23 20:14:45 · 1896 阅读 · 1 评论 -
Leetcode 121:买卖股票的最佳时机
原题:给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。注意你不能在买入股票前卖出股票。示例 1:输入: [7,1,5,3,6,4]输出: 5解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。 注意利...原创 2018-04-22 11:07:44 · 6830 阅读 · 1 评论 -
Leetcode 322: Coin Change - 动态规划
Description:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that am...原创 2018-08-30 15:51:01 · 261 阅读 · 0 评论