摘要: Unique Binary Search TreesGivenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2014-04-01 21:43 boole 阅读(125) 评论(0) 推荐(0)
摘要: Best Time to Buy and Sell Stock IISay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not e 阅读全文
posted @ 2014-04-01 21:41 boole 阅读(111) 评论(0) 推荐(0)
摘要: Reverse IntegerReverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321public class Solution { public int reverse(int x) { int positive = 1; int result = 0; if(x 0) { result = result*10 + x%10; x ... 阅读全文
posted @ 2014-04-01 21:40 boole 阅读(136) 评论(0) 推荐(0)
摘要: Same TreeGiven 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./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode... 阅读全文
posted @ 2014-04-01 21:38 boole 阅读(113) 评论(0) 推荐(0)
摘要: Maximum Depth of Binary TreeGiven 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./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode righ... 阅读全文
posted @ 2014-04-01 21:36 boole 阅读(77) 评论(0) 推荐(0)
摘要: Single NumberGiven an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?public class Solution { public int singleNumber(int[] A) { int a = 0;... 阅读全文
posted @ 2014-04-01 21:35 boole 阅读(129) 评论(0) 推荐(0)
摘要: 什么是shell? 什么是脚本? 就是一些文件,我们能将一系列需要执行的命令写入其中,然后通过shell来执行这些脚本。通常使用某种基于解释其的编程语言。一般shell脚本是以一个#!为开头的文本文件,如#!/bin/bash,/bin/bash是bash的路径。运行脚本文件方式如下: $ sh script.sh 或者 # sh script.sh #该命令行默认该脚本在该目录下,也可以使用以“./” 或“/”开头的相对路径和绝对路径表示方式区别在于,前者$代表普通权限用户,#代表root权限用户。后半部分以#开始,代表注释。对shell脚本有了初步认识后,开始正式进入shell脚本... 阅读全文
posted @ 2014-03-17 17:42 boole 阅读(183) 评论(0) 推荐(0)
摘要: DescriptionGeorge took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which comp 阅读全文
posted @ 2014-03-11 10:57 boole 阅读(147) 评论(0) 推荐(0)
摘要: from urllib2 import Request, urlopen, URLErrorreq = Request(someurl)try: response = urlopen(req)except URLError, e: if hasattr(e, 'reason'): print 'We failed to reach a server.' print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The server couldn/'t fu 阅读全文
posted @ 2013-09-13 01:06 boole 阅读(846) 评论(0) 推荐(0)
摘要: Python读写文件Python读写文件1.open使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件。file_object = open('thefile.txt')try: all_the_text = file_object.read( )finally: file_object.close( )注:不能把open语句放在try块里,因为当打开文件出现异常时,文件对象file_object无法执行close()方法。2.读文件读文本文件input = open('data',  阅读全文
posted @ 2013-09-11 22:28 boole 阅读(212) 评论(0) 推荐(0)