自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Leetcode 156 Binary Tree Upside Down

Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin

2016-01-28 23:04:44 362

原创 Leetcode 298 Binary Tree Longest Consecutive Sequence

给一个binary tree, 问你怎么找其中最长的连续递增的path.也可以从前往后的遍历。然后用递归变成从后往前http://www.chenguanghe.com/binary-tree-longest-consecutive-sequence/

2016-01-28 23:03:24 400

原创 Leetcode 270 Closest Binary Search Tree Value

Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note: Given target value is a floating point. You are guaranteed to have only one u

2016-01-28 22:59:52 339

原创 Leetcode 250 Count Univalue Subtrees

Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given binary tree, 5

2016-01-28 22:54:25 735

原创 Leetcode 287. Find the Duplicate Number

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,

2016-01-28 22:43:29 605

转载 Leetcoed 277 Find the Celebrity

Find the CelebrityTotal Accepted: 1126 Total Submissions: 3603 Difficulty: MediumSuppose you are at a party with n people (labeled from 0 ton - 1) and among them, there may exi

2016-01-28 13:43:20 445

原创 Leetcode 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you

2016-01-28 12:50:38 271

原创 Leetcode Two Sum II – Input array is sorted (Java)

When the array is sorted, when we want to do the sum to the target. we can scan from both sides.public int[] twoSum(int[] numbers, int target) { if (numbers == null || numbers.length == 0) return

2016-01-28 12:00:43 380

原创 Leetcode Wiggle Sort

Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4]./先将Array排序,然后进行两两互换。最后的结

2016-01-28 11:56:31 301

原创 Leetcode 14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.首先找到字符数组中最短的字符长度,然后取第一个字符串,开始从第一个字符开始遍历,如果遇到一个字符不统一,就返回从0到那个字符位置的字符串作为结果public class Solution { public Str

2016-01-28 11:29:33 296

原创 Leetcode 31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2016-01-28 04:58:52 295

原创 Leetcode 34. Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found

2016-01-28 04:44:51 264

原创 Leetcode 120. 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.For example, given the following triangle[ [2], [3,4], [

2016-01-28 04:25:57 260

原创 Leetcode 102. 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).For example:Given binary tree {3,9,20,#,#,15,7},用一个栈维护一层的节点public Array

2016-01-27 11:30:36 333

原创 Leetcode tree题型总结

对我来说,Tree 是 Leetcode中最简单的题,因为Tree的题型比较单一,方法也比较固定。98. Validate Binary Search Tree https://leetcode.com/problems/validate-binary-search-tree/我觉得这道题和Symmetric Tree比较像都是考察树的结构,要判断这个需要判断左右节点,采用从底

2016-01-27 11:28:21 829

原创 Leetcode Greedy 题型总结

我自己对Greedy不是很熟悉https://en.wikipedia.org/wiki/Greedy_algorithm觉得greedy题也没有规律可以遵循,所以比较难比如134. Gas Stationhttps://leetcode.com/problems/gas-station/如何判断从哪里开始开,就是很难,如何判断在给定的Gas和Cost的情况下能够跑完所

2016-01-27 09:49:26 1053

原创 Leetcode 316. Remove Duplicate Letters

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a

2016-01-27 09:22:05 499

原创 Leetcode 210. Course Schedule II

There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as

2016-01-27 01:46:38 308

原创 Leetcode 207. Course Schedule

There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as

2016-01-27 01:43:57 351

原创 Depth-first-search的总结

几个技巧,在树中的先序遍历就是对应的Depth-first-search.100. Same Tree https://leetcode.com/problems/same-tree/遍历树的节点,判断树节点的node的val是否一致,并且递归判断左右孩子301. Remove Invalid Parentheses   https://leetcode.com/p

2016-01-27 01:38:56 629

原创 Leetcode 124. Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The

2016-01-27 01:36:15 321

原创 114. Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:analysis

2016-01-27 01:28:23 322

原创 Leetcode 98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th

2016-01-27 01:13:35 379

原创 Leetcode 101. Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric:Analysis: 判断左右的节点是否对称/** * Definition for a binary

2016-01-27 01:05:14 307

原创 Leetcode 187. Repeated DNA Sequences

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri

2016-01-27 00:41:03 313

原创 Leetcode 326. Power of Three

Given an integer, write a function to determine if it is a power of three.这个是Power of two 的兄弟题,他的兄弟可以用Bit Manipulation做,但是它不可以这里用了DFS搜索做public class Solution { public boolean isPowerOfThree(

2016-01-25 13:01:43 348

原创 Leetcode Bit Manipulation 题型总结

Leetcode136. Single Number https://leetcode.com/problems/single-number/137. Single Number II https://leetcode.com/problems/single-number-ii/260. Single Number III https://leetcode.com/proble

2016-01-25 12:56:17 412

原创 Leetcode 85. Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.Analysis:需要结合Stack,进行压栈和出栈等操作。最有技巧的一点就是利用Dynamic Programming, 统计在二维数组中连续一的个数。然后

2016-01-25 12:38:49 261

原创 Leetcode 150. Evaluate Reverse Polish Notation

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:import java.u

2016-01-25 12:24:14 279

原创 Leetcode 225. Implement Stack using Queues

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet

2016-01-25 12:16:31 262

原创 Leetcode 155. Min Stack

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() -- Get

2016-01-25 12:03:51 316

原创 Leetcode 316. Remove Duplicate Letters

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a

2016-01-25 11:56:58 442

原创 Leetcode 71. Simplify Path

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did

2016-01-25 11:25:10 292

原创 Leetcode Stack总结

20. Valid Parentheses   https://leetcode.com/problems/valid-parentheses/现在看到括号就想用stack判断了,因为它是个后入先判断的节奏42. Trapping Rain Water 这道题我更想把它称作Dynamic Programming的题https://leetcode.com/problems/trap

2016-01-25 06:54:43 630

原创 Leetcode HashTable 题型总结

HashSet 来检测数组元素的唯一性36. Valid Sudoku https://leetcode.com/problems/valid-sudoku/   136. Single Number   https://leetcode.com/problems/single-number/应该使用位运算30. Substring with Concatenation of

2016-01-25 06:34:00 640

原创 Leetcode 204. Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.这个题有考数学的感觉,使用dynamic programming 应该是一种比较好的解法,从2开始,依次将prime number 的倍数置为不是prime number.对于prime number 不置,因为当

2016-01-25 06:30:53 315

原创 Leetcode 37. Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku

2016-01-25 06:05:12 289

原创 Leetcode 36. Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.数独的规则是同行,同列,或者是每一个小

2016-01-25 05:51:01 312

原创 Leetcode 242. Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.同形词,实质是统计在单词中每个字符出

2016-01-25 05:45:48 327

原创 Leetcode 151. Reverse Words in a String

Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place 

2016-01-24 12:14:08 285

空空如也

空空如也

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

TA关注的人

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