自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 windows下安装pip

首先下载这个  http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz然后解压  在cmd下切换到解压目录运行python setup.py install

2015-11-16 11:38:55 524

原创 LeetCode257 BinaryTreePaths(打印根节点到叶子节点的左右路径) Java题解

题目:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]

2015-08-20 21:44:37 1855

原创 LeetCode242_Valid Anagram(判断两个字符串是不是由完全一样字符组成) Java题解

题目: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.Note:Yo

2015-08-20 14:33:59 1808

原创 LeetCode96_Unique Binary Search Trees(求1到n这些节点可以组成多少种不同的二叉查找树) Java题解

题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2

2015-08-20 14:19:07 1531

原创 HashMap源码分析

一,HashMap的成员变量1,//默认的初始容量,2的4次方=16 static final int DEFAULT_INITIAL_CAPACITY = 1 4; 2,//最大容量,2的30次方  1个G  static final int MAXIMUM_CAPACITY = 1 30;3,//Entry数组,每一个元素都是键值对应的对

2015-08-03 15:15:57 515

原创 LeetCode147_Insertion Sort List(用插入排序算法对链表进行排序) Java题解

题目:Sort a linked list using insertion sort.题解:插入排序就是先对一部分进行排序 排序好后将未排序的插入到已经排序好的队列中  在插入的时候  如果是数组的话可以从前往后  也可以从后往前  对于链表就只能是前者了代码:public static ListNode insertionSortList(ListNode

2015-07-30 16:38:54 4340 1

原创 LeetCode108_Convert SortedArray to BinarySearchTree(将有序数组转成二叉排序树) Java题解

题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题解:和我上面一篇将有序链表转成二叉排序树中用哈希表解的方法是一样的,基本思路:链表中间那个节点为树的根节点,根节点的左子树节点应该是根节点左边那部分的中间节点,根节点的右节点应该是根

2015-07-30 09:19:54 1514

原创 LeetCode109_Convert Sorted List to Binary Search t题目tiTree(将链表转成二叉排序树) Java题解

题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.题解:将一个有序链表转成二叉排序树,如果是一棵相对平衡的排序树,应该是这样的,链表中间那个节点为树的根节点,根节点的左子树节点应该是根节点左边那部分的中间节点,根节点的

2015-07-30 08:56:04 833

原创 LeetCode234_PalindromeLinkedList (判断是否为回文链表) Java题解

题目:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?题解:判断一个链表是不是回文的,这里要求O(n)时间复杂度和O(1)的空间时间复杂度,总共想了三种办法,三种办法都用到了两个指针,符合

2015-07-29 11:40:29 6747 2

原创 LeetCode237_Delete Node in a Linked List(删除链表中的节点) Java题解

题目:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node

2015-07-29 09:02:05 855

原创 LeetCode201 Bitwise AND of Numbers Range Java 题解

题目:Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.解答:假如说5:101  7:111  连续几个数相与的规律:一,只要是相同的位置的数字不相同最后那个位置的结果一定是0 。二,如果高位不相同,从不相同的那位到最低位都会为0,例如5和7虽然第0

2015-07-16 20:29:37 868

原创 LeetCode222 Count CompleteTree Nodes(计算完全二叉树的节点数) Java 题解

题目: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 completel

2015-07-09 20:51:26 1933

原创 LeetCode103 BinaryTreeZigzagLevelOrderTraversal(二叉树Z形层次遍历) Java题解

题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Give

2015-07-09 17:08:19 1159

原创 LeetCode232 Implement Queue using Stacks Java 题解

题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front eleme

2015-07-09 12:03:51 2870

原创 LeetCode225 Implemet Stack using Queues Java题解

题目: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() -- Re

2015-07-09 11:58:05 830

原创 LeetCode145 Binary Tree Postorder Traversal Java题解(递归 迭代)

题目:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].解题:递归的还是和前面中

2015-07-09 10:34:20 1635

原创 LeetCode144 Binary Tree PreOrder Traversal Java题解(递归 迭代)

题目:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].解题:先序遍历二叉树  和

2015-07-08 16:18:46 727

原创 LeetCode94 BinaryTreeInorderTraversal Java题解(递归 迭代)

题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].解题:中序遍历一颗二叉树,如

2015-07-08 09:57:06 1499

原创 LeetCode110 Blanced Binary Tree Java 题解

题目: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 node ne

2015-07-06 22:01:02 547

原创 LeetCode107 Binary Tree Level Order Traversal II

题目: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,9,20,#,

2015-07-06 21:29:24 497

原创 LeetCode102 Binary Tree Level Order Traversal Java题解

题解: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}, 3 / \ 9

2015-07-06 21:13:28 885

原创 LeetCode100 SameTree java题解

题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解题:

2015-07-06 19:55:23 892

原创 LeetCode101 SynmetricTree Java题解

题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3

2015-07-06 19:43:06 525

原创 LeetCode226 InvertBinaryTree Java题解

题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1解答:遍历每一个节点  直接交换他们的左右节点代码:public static TreeNode invertTr

2015-07-06 16:42:58 555

原创 LeetCode151_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".注意的地方:What constitutes a word?A sequence of non-space

2015-07-06 15:58:06 496

原创 LeetCode104_MaximumDepthofBinaryTree Java题解

题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解题:求最大深度  和前面一题类似  用递归遍历就

2015-07-06 15:14:38 597

原创 LeetCode111 MinmumDepthofBinaryTree java 题解

题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.解题:求根节点到最近的叶子节点之间的距离用

2015-07-06 15:03:31 588

原创 LeetCode112 PathSum Java题解

题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree

2015-07-06 10:58:52 968

原创 LeetCode172_FactorialTrailingZeroes java题解

题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.解答:求N!后面有多少个零,这题考的主要是数学,举一个简单例子102!=1*2*3*4*5  *6*7*8*9*10

2015-07-03 11:30:36 577

原创 LeetCode224 BasicCalculator java题解

题目: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

2015-07-02 21:52:24 669

原创 LeetCode219 ContainsDuplicateII java题解

题目:Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is a

2015-07-02 17:50:06 672

原创 LeetCode229 MajorityElementII java题解

题目: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.求出现次数大于三分之一数组的长度,所以最多就只有2个这样的元素,题目要求线性时间复杂度和常数的空

2015-07-01 20:39:56 684

原创 求最长有效括号长度 java

题目:输入只包含圆括号的字符串,找出最长的合法括号子串的长度比如:“(()”——》2,最长的有效子串是“()”“)()())”——》4,最长的有效子串是“()()”解题思路:如果输入是左括号就直接入栈,如果是右括号,如果此时栈为空或此时的栈顶不为左括号就不作处理同时把记录有效长度的临时变量置为0,如果栈顶为左括号则出栈并把记录有效长度的临时变量加2.最后返回最大的记录长

2015-07-01 08:45:39 2410

原创 LeetCode71 Simplify Path java题解

题目:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"题解:解题思路:这题是简化目录,每一级目录前面都有一个斜杠,我可以首先对斜杠进行分割,分割之后

2015-07-01 08:11:03 1859

原创 java 中缀转后缀(逆波兰)

import java.util.Stack;public class LeetCode_middleTransformToReversePolish { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String[] in

2015-06-30 20:02:33 1041

原创 LeetCode150 Evaluate Reverse Polish Notation java题解

题目: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: ["

2015-06-30 10:13:32 606

原创 LeetCode85 Maximal Rectangle java题解

public static int maximalRectangle(char[][] matrix) { int rowNum=matrix.length; if(rowNum==0) return 0; int columnNum=matrix[0].length; int[][] height=new int[rowNum][colum

2015-06-30 09:01:46 1306

原创 LeetCode84 Largest Rectangle in Histogram java题解

题目:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram wher

2015-06-27 11:21:16 1220

原创 LeetCode155 MinStack java题解

题目: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(

2015-06-17 20:14:09 447

原创 LeetCode20 Valid Parentheses的java 题解

题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are

2015-06-17 16:36:04 413

空空如也

空空如也

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

TA关注的人

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