自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 二叉树的前/中/后序遍历算法(非递归)

都由堆栈实现,如下:先序:public List preorderTraversal(TreeNode root) { Stack stack=new Stack(); TreeNode rot=root; List list=new ArrayList(); while(rot!=null||!stack.empty()) {

2017-03-27 22:30:32 373

原创 Spark环境搭建

玩Spark也有一段时间了,简单总结一下spark集群的配置信息,网上有许多参考教程,但是每个似乎配出来都有点小问题,这里总结一下我的配置:     spark是大数据计算框架,不具备数据存储功能,因此一般spark与Hadoop是搭配使用的,想要搭建spark环境需要先搭建hadoop的环境,首先我们配置一下节点信息,在/etc/hosts中配置节点ip地址与名称,我这里用了两个节

2016-10-25 16:47:29 587

原创 leetcode Candy

需要考虑升序和降序两种情况,升序比较好办,我们只需要将前一个索引位置的candy+1即可,如果是降序就比较麻烦,我们可以举个例子:5 4 3 2我们默认第一个位置5的初始值candy肯定是1,但当到4的时候,发现5给的1个candy太少了,需要+1,同理到3的时候,发现5和4给的candy太少了,需要分别+1,也就是当降序的时候我们需要不断修正结果,以得到正确结果,而很明显,这个修正的数与

2016-09-08 11:13:31 285

原创 leetcode Interleaving String

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r

2016-09-08 10:12:37 224

原创 leetcode N-Queens II

Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.两道题思路基本一样,第二题的代码比较整洁,思路是用一个res[n]数组,其中res[i]的值代表第i行的queen摆放的列的位置,我们

2016-09-07 12:06:21 207

原创 leetcode Count of Range Sum

Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j),

2016-09-06 21:42:41 229

原创 leetcode LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if

2016-09-06 09:09:42 270

原创 leetcode Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements

2016-09-05 20:32:09 292

原创 leetcode Edit Distance

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 permitted on a word:

2016-09-05 18:53:41 208

原创 Closest Binary Search Tree Value II

Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.Note:Given target value is a floating point.You may assume k is always valid,

2016-09-03 18:27:46 221

原创 leetcode Word Pattern II

291. Word Pattern II QuestionEditorial Solution My SubmissionsTotal Accepted: 7720Total Submissions: 21299Difficulty: HardGiven a pattern and a string str, find i

2016-09-03 18:11:02 241

原创 leetcode Paint House II

There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two

2016-09-03 13:15:17 270

原创 leetcode Longest Substring with At Most K Distinct Characters

Given a string, find the length of the longest substring T that contains at most k distinct characters.For example, Given s = “eceba” and k = 2,T is "ece" which its length is 3.code:

2016-09-02 14:38:57 222

原创 leetcode 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-09-02 14:10:11 161

原创 leetcode 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-09-01 19:08:29 191

原创 leetcode Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu

2016-09-01 17:14:21 177

原创 leetcode Range Sum Query-Mutable

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.Examp

2016-09-01 16:26:44 197

原创 leetcode Add and Search Word - Data structure design

Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only lett

2016-09-01 14:19:03 173

原创 leetcode Simplify Path

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"遇到..需要返回上一级目录,遇到.和/直接忽略,用堆栈保存路径,代码:public String s

2016-09-01 12:19:25 186

原创 leetcode Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0

2016-08-31 14:29:27 174

原创 leetcode Reconsrtuct Itinerary

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus

2016-08-30 20:26:01 160

原创 leetcode Additive Number

Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the

2016-08-30 19:24:29 205

原创 leetcode Basic Calculator II

Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces. The integer division should

2016-08-30 17:10:09 170

原创 leetcode Basic Calculator

Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em

2016-08-30 12:18:15 229

原创 leetcode Repeated DNA Sequence

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.Write

2016-08-29 19:24:45 362

原创 leetcode Majority Element II

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space摩尔投票法,如果不了解这个方法想自己想我觉得真是挺难的,关于摩尔投票法http://mabusy

2016-08-22 22:03:29 186

原创 leetcode Palindrome Partioning II

Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu

2016-08-22 19:37:35 330

原创 leetcode 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-08-22 18:05:37 161

原创 leetcode 关于全排列题目的简单总结

266Palindrome Permutation 52.6% Easy46Permutations37.7% Medium267Palindrome Permutation II 29.5% Medium

2016-08-21 22:18:19 3993

原创 leetcode Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille

2016-08-21 13:44:41 210

原创 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 mini

2016-08-21 12:50:01 164

原创 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

2016-08-20 19:17:45 163

原创 leetcode 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 vertically. You may assu

2016-08-15 21:30:07 159

原创 leetcode Construct Binary Tree from Inorder and Postorder Traversal

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-08-15 16:18:57 142

原创 leetcode Bitwise AND of Numbers Range

Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.Credits:Special thanks to @amrsaqr for adding this problem and creating all test cases.可以这样想,只要m!=n,m与n之间的

2016-08-12 11:48:30 183

原创 leetcode Find the Celebrity

Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her but

2016-08-12 10:35:21 251

原创 leetcode Game Of Life

According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m 

2016-08-10 20:16:38 183

原创 leetcode Convert SortedList to BST

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.这道题本来开一个数组储存list然后进行递归构造BST还是比较简单的,但是网上看到一个空间复杂度O(1)的算法,同样是递归,但取链表中间节点的方式十分巧妙,所以在这里贴出来:

2016-08-09 19:53:21 199

原创 leetcode 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: 1 \

2016-08-09 17:38:30 151

原创 leetcode Graph Valid Tree

Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n =

2016-08-08 21:55:04 477

空空如也

空空如也

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

TA关注的人

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