LeetCode
yoyocheknow
菜鸟一枚
展开
-
LeetCode之复制有random指针的链表Copy List with Random Pointer
问题描述:/** * A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. * Return a deep copy of the list. */给你一个链表,这个链表不仅有next指原创 2016-07-22 12:44:20 · 2748 阅读 · 0 评论 -
LeetCode之前序迭代遍历
问题描述:/** * Given a binary tree, return the preorder traversal of its nodes' values. * * For example: * Given binary tree {1,#,2,3}, * 1 * \ * 2 * / * 3 * return [1,2,3]. * * Note:原创 2016-07-19 09:27:14 · 2354 阅读 · 0 评论 -
LeetCode之分糖果
问题描述:/** * There are N children standing in a line. Each child is assigned a rating * value. You are giving candies to these children subjected to the following * requirements: * * Each child mus原创 2016-07-19 11:32:36 · 3267 阅读 · 0 评论 -
LeetCode之爬梯子
问题描述:/** * 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? */一共有N阶梯子,每次原创 2016-07-19 14:38:29 · 3333 阅读 · 0 评论 -
LeetCode之克隆图
问题描述:/** * Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. * * OJ's undirected graph serialization: * Nodes are labeled uniquely. * * We use # as原创 2016-07-19 17:52:34 · 3378 阅读 · 0 评论 -
LeetCode之组合数
问题描述:/** * Given two integers n and k, return all possible combinations of k numbers out * of 1 ... n. For example, If n = 4 and k = 2, a solution is: * * [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4原创 2016-07-20 11:44:08 · 3273 阅读 · 0 评论 -
LeetCode之求组合数之和CombinationSum
问题描述:/** * Given a set of candidate numbers (C) and a target number (T), find all unique * combinations in C where the candidate numbers sums to T. * * The same repeated number may be chosen from原创 2016-07-20 18:10:31 · 2588 阅读 · 0 评论 -
LeetCode之求组合数之和二CombinationSumII
问题描述:/** * Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. * * Each number in C may only be used once i原创 2016-07-21 10:48:15 · 2520 阅读 · 0 评论 -
LeetCode之通过二叉树的中序遍历和后序遍历还原二叉树
问题描述:/** * Given inorder and postorder traversal of a tree, construct the binary tree. * * Note: * * You may assume that duplicates do not exist in the tree. * */根据给出的二叉树的中序遍历和后序遍历的结果,来还原这棵二叉树原创 2016-07-21 14:48:43 · 3245 阅读 · 0 评论 -
LeetCode之通过二叉树的中序遍历和前序遍历来还原二叉树
问题描述:/** * Given preorder and inorder traversal of a tree, construct the binary tree. * * Note: * * You may assume that duplicates do not exist in the tree. */根据给出的二叉树的中序遍历和前序遍历的结果,来还原这棵二叉树,假定这原创 2016-07-21 15:24:26 · 3486 阅读 · 0 评论 -
Java堆与栈的区别
转载博文链接: http://my.oschina.net/u/1464779/blog/225590我想这篇足以让大家很清晰理解Java的栈和堆栈的区别。下面的是我收集了好多网友的资料加以整理的。Java 中的堆和栈 Java把内存划分成两种:一种是栈内存,一种是堆内存。 1.栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。与C++不同,Java自动管理栈和堆,程序转载 2016-08-04 15:05:02 · 2463 阅读 · 0 评论 -
LeetCode之根据序列求平衡二叉树
问题描述:/** * Given an array where elements are sorted in ascending order, convert it to a height balanced BST. */给你一个升序的序列,根据这个序列来构造一个平衡二叉树。 解题思路就是先找到根节点,然后递归找到左右子节点。 代码如下:public static TreeNode sort原创 2016-07-22 09:50:46 · 5124 阅读 · 0 评论 -
LeetCode之根据升序的单链表构造平衡二叉树
问题描述:/** * Given a singly linked list where elements are sorted in ascending order, * convert it to a height balanced BST. */给你一个升序的单链表来构造一个平衡二叉树。这个题目和上面那篇博文不一样在上面那篇博文是给了一个升序的数组,而这次是单链表。 解题思路依然是先找到原创 2016-07-22 10:35:38 · 2595 阅读 · 0 评论 -
LeetCode之后序迭代遍历
问题描述:/** * Given a binary tree, return the postorder traversal of its nodes' values. * * For example: * Given binary tree {1,#,2,3}, * 1 * \ * 2 * / * 3 * return [3,2,1]. * *原创 2016-07-18 17:42:03 · 2531 阅读 · 0 评论 -
LeetCode之求二叉树最大路径和
问题描述:/** * Given a binary tree, find the maximum path sum. * * The path may start and end at any node in the tree. * * For example: Given the below binary tree, * * 1 * / \ * 2 3 *原创 2016-07-18 16:59:59 · 3585 阅读 · 0 评论 -
LeetCode之二叉树按层从下往上遍历
题目描述:/** * Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). * * For example: * Given binary tree {3原创 2016-07-18 11:38:19 · 5785 阅读 · 1 评论 -
LeetCode之count-and-say sequence
问题描述:/** * The count-and-say sequence is the sequence of integers beginning as follows: * 1, 11, 21, 1211, 111221, ... * * 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is r原创 2016-07-22 14:56:33 · 3397 阅读 · 0 评论 -
LeetCode之计算解密的数量DecodeWays
问题描述:/** * A message containing letters from A-Z is being encoded to numbers using the * following mapping: * * 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, * deter原创 2016-07-22 16:14:15 · 2480 阅读 · 0 评论 -
LeetCode之链表数相加
问题描述:/** * You are given two linked lists representing two non-negative numbers. * * The digits are stored in reverse order and each of their nodes contain a single digit. * * Input: (2 -> 4 ->原创 2016-07-13 16:14:35 · 2535 阅读 · 0 评论 -
LeetCode 之Distinct Subsequences
问题描述:/** * Distinct Subsequences * Given a string S and a string T, count the number of distinct subsequences of T in S. * * A subsequence of a string is a new string which is formed from the ori原创 2016-07-25 13:57:00 · 2470 阅读 · 0 评论 -
LeetCode之判断高度平衡二叉树
先看问题描述:/** * Given a binary tree, determine if it is height-balanced. * For this problem, a height-balanced binary tree is defined as a binary tree * in which the depth of the two subtrees of every原创 2016-07-14 14:09:53 · 4969 阅读 · 0 评论 -
LeetCode之操作两个数相除DivideTwoIntegers
问题描述:/** * Divide two integers without using multiplication, division and mod operator. */让两个数相除,不使用乘法,除法,和取余的方法。 比如这样两个数:35和4.我们知道35除以4等于8余3。 一个思路就是辗转相减法,即每次让35减4,知道小于0,期间有一个count来统计减掉了多少次4,也就是35有多原创 2016-07-25 16:48:19 · 2642 阅读 · 0 评论 -
LeetCode之买卖股票
先看第一种买卖规则:/** * 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 sel原创 2016-07-14 18:03:18 · 2659 阅读 · 0 评论 -
LeetCode之计算字符串相似度或编辑距离EditDistance
问题描述:/** * Given two words word1 and word2, find the minimum number of steps required to * convert word1 to word2. (each operation is counted as 1 step.) * * You have the following 3 operations pe原创 2016-07-26 12:39:16 · 4751 阅读 · 0 评论 -
LeetCode之EvaluateReversePolishNotation
问题描述:/** * Evaluate the value of an arithmetic expression in Reverse Polish Notation. * * Valid operators are +, -, *, /. Each operand may be an integer or another expression. * * Some examples:原创 2016-07-26 14:46:50 · 2450 阅读 · 0 评论 -
LeetCode之查找第一个未出现的正整数
问题描述:/** * Given an unsorted integer array, find the first missing positive integer. * * For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. * * Your algorithm should run in O(n) time原创 2016-07-26 15:53:54 · 4464 阅读 · 0 评论 -
LeetCode之flatten binary tree
问题描述:/** * Given a binary tree, flatten it to a linked list in-place. * * For example, * Given * * 1 * / \ * 2 5 * / \ \ * 3 4 6 * The flattened tree should原创 2016-07-26 17:09:56 · 2560 阅读 · 0 评论 -
LeetCode之二叉树中序迭代遍历
问题描述:/** * For example: Given binary tree {1,#,2,3}, * 1 * \ * 2 * / * 3 * return [1,3,2]. * * Note: Recursive solution is trivial, could you do it iteratively? */题目说,递归解法很easy。要让用迭代的方法进行原创 2016-07-18 10:01:04 · 2706 阅读 · 0 评论 -
LeetCode之二进制字符串相加
刚开始刷leetcode,第一道题是给两个二进制的字符串,求这两个二进制相加以后的和,输出当然也是二进制的格式了。以下是题目:/** * Given two binary strings, return their sum (also a binary string). * * For example, a = "11" b = "1" Return "100". */解决这个问题,首先原创 2016-07-13 10:24:10 · 6031 阅读 · 0 评论