
leetcode
文章平均质量分 57
humanleelxy
这个作者很懒,什么都没留下…
展开
-
Leetcode Median of two sorted arrays解题
Q4 Median of two sorted array首先奉上题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh原创 2017-09-14 15:55:28 · 247 阅读 · 0 评论 -
Leetcode Longest Increasing Subsequences
题目描述Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101],原创 2017-12-19 14:20:58 · 174 阅读 · 0 评论 -
Leetcode evaluate Division
题目Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answer原创 2018-01-11 21:13:10 · 309 阅读 · 0 评论 -
Leetcode Jump Game
题目Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i原创 2018-01-11 21:28:46 · 192 阅读 · 0 评论 -
Leetcode Unique BST
题目给定正数n,计算1到n组成不同的BST的个数。题目分析BST的特点是左子树小于根, 右子树大于根,这是一个递归的定义。因此我们也可以采用递归的反方向,自下而上的递推出不同BST的个数。首先计算1个结点的BST个数,接下来计算2个,3个,……直到计算完n个结点。建立两个数组,cnt[i]和dp[i][j],cnt[i]表示i个结点能够组成不同的BST的个数,dp[i][j]表示给出i个结点,以j为原创 2017-12-19 15:35:13 · 222 阅读 · 0 评论 -
Leetcode freedom trail
题目In the video game Fallout 4, the quest “Road to Freedom” requires players to reach a metal dial called the “Freedom Trail Ring”, and use the dial to spell a specific keyword in order to open the door原创 2018-01-12 11:55:19 · 357 阅读 · 0 评论 -
Leetcode Merge k sorted lists
题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目分析将k个已经排好序的链表合并成一个sorted的链表。可以采用归并排序的思想: 1. 读出k个链表的链表头,并比较它们的大小 2. 取出最小的那个链表头,并将它连接到新链表的尾部 3. 重复原创 2018-01-03 20:36:57 · 202 阅读 · 0 评论 -
Leetcode 分治法
分治法分治法的思想是将问题分而治之: 1. 将问题分成小问题 2. 分治完毕后,触发递归中的结束判定语句 3. 将分治的结果 合并一起求majority题目Given an array of size n, find the majority element. The majority element is the element that appears more th原创 2018-01-05 10:01:41 · 395 阅读 · 0 评论 -
Leetcode minimum height trees
题目For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called min原创 2018-01-07 10:50:23 · 191 阅读 · 0 评论 -
Leetcode 股票交易
股票交易系列共有三道题目,难度递增。1题Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell原创 2017-12-19 14:17:34 · 595 阅读 · 0 评论 -
Leetcode Ugly numbers
题目Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ug原创 2017-12-31 23:30:27 · 154 阅读 · 0 评论 -
Leetcode 初探
Add Two Numbers第一次在leetcode上面做题,选了两道最简单的题目来试试手,回忆一下cpp的写法。写了一个暑假的python之后,在cpp语法上稍微有点不太习惯,还好,做完前两道题就上手了。这里主要讲一讲Question2. 题目原意: You are given two non-empty linked lists representing two non-n原创 2017-09-09 18:12:07 · 214 阅读 · 0 评论 -
ZigZag Conversion
题目意思是将字符串变成Z型字符串这道题一开始我是想着通过计算下一步取的字符所在的位置来构成zigzag字符串。解题思路: 1. 首先进行特殊情况处理,如果len(字符串长度)小于行数,或者行数等于1输出它本身 2. 接下来分成s.length() / numRows个小片,每片长度为2*(numRows-1) 3. 由于在切片过程中容易忽略掉s.length()==sliceLen原创 2017-09-20 20:21:56 · 195 阅读 · 0 评论 -
leetcode easy题page1小结
Intro之前一直埋头于leetcode的medium和hard难度的题目,今天想变化一下,将第一页的easy题刷完,并小结一下。Q7 reverse integerDescription: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reverse原创 2017-09-28 14:26:16 · 276 阅读 · 0 评论 -
Leetcode Arithmetic Slices
题目: A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.A zero-indexed array A consisting of N nu原创 2017-11-08 15:41:06 · 182 阅读 · 0 评论 -
判断BST是否合法
题目介绍:二叉搜索树(BST)的结构是左子树的值小于根值,右子树的值小于根值。解题思路二叉搜索树的定义本身就是递归的,因此,在这种情况下,用递归的方法去判断每一个子树是否合法最恰当。 从上图可以看出:左子树的最深右子树必须小于根值,右子树的最深左子树必须大于根值。同时在递归的时候判断左子树要小于父节点的值,右子树要大于父节点的值即可。源代码/** * Definition for a bin原创 2017-10-16 08:48:24 · 1325 阅读 · 0 评论 -
Leetcode House Robber
House Robber I题目描述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 th原创 2017-10-26 14:10:49 · 259 阅读 · 0 评论 -
Leetcode Minimum path sum
题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.题目解析: 这道题第一眼看到minimum path马上就可以联想到最小生成树,可以将这一个原创 2017-11-05 17:52:44 · 242 阅读 · 0 评论 -
Leetcode Triangle
题目描述Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.解题思路原创 2017-11-26 15:25:51 · 336 阅读 · 0 评论 -
Leetcode 01 Matrix
题目给出一个矩阵,寻找最近的零题目解析找出最近的零,相当于寻找一个最短路径的问题,有两种想法思想一暴力求解: 1. 先把0的位置存起来 2. 遇到1时,将每个1和0的欧式距离求出,取最小值 3. 返回最新的矩阵 这种思想马上会超时。class Solution {public: vector<vector<int> > updateMatrix(vector<vector<int原创 2018-01-07 11:49:52 · 207 阅读 · 0 评论