自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 文件读写

文件读写一直都是常用工具,但是也是经常出问题的地方,现总结一二1. 创建文件在库函数中有个File.create(filename)用于创建一个文件,但是如果没有对应Folder的情况下会抛异常System.IO.DirectoryNotFoundException,所以在每次新建文件是,最好创建Folder, string subF

2016-05-11 18:53:53 664

原创 Reservoir sampling(水塘抽样)

题目1:给出一个数据流,这个数据流的长度很大或者未知。并且对该数据流中数据只能访问一次。请写出一个随机选择算法,使得数据流中所有数据被选中的概率相等。对于复杂问题一定要学会归纳总结,即从小例子入手,然后分析,得出结论,然后在证明。不然遇到一个抽象问题,不举例感觉这个问题,直接解还是比较难的。对于此问题的难处就是数据流的长度未知,如果已知,so easy。现在进行归纳总结:1)

2015-09-11 15:28:36 6899 1

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

2015-08-30 13:23:37 1030

原创 LeetCode-Number of Digit One(编程之美-1的数目)

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the followin

2015-08-29 18:05:33 2241 1

原创 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", ret

2015-08-28 17:48:18 1012

原创 LeetCode-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 original string by deleting some (can be non

2015-08-28 15:21:03 850

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

2015-08-27 20:02:41 783

原创 LeetCode-Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 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

2015-08-27 17:45:34 829

原创 LeetCode-Ugly Number

Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly si

2015-08-27 17:05:39 922

原创 LeetCode-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], [

2015-08-27 14:34:47 851

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

2015-08-25 19:57:08 1020

原创 LeetCode-Best Time to Buy and Sell Stock I II III IV

此处的三个题跟Maximum Subarray,可以先看此题I)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, b

2015-08-25 17:46:27 1051

原创 LeetCode-Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha

2015-08-25 15:59:19 1082

原创 LeetCode-N-Queens

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.

2015-08-22 17:29:00 1048

原创 LeetCode-Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of

2015-08-21 11:43:47 872

原创 LeetCode-Generate Parentheses & Letter Combinations of a Phone Number

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()

2015-08-20 14:20:53 1027

原创 Egg dropping puzzle

问题:有一个100层高的楼,如果一个鸡蛋从n层掉下来或者n层以上,鸡蛋就会碎掉。已知,现在有两个鸡蛋,找到满足条件的n,使在最坏情况下,丢鸡蛋的次数最少。原题链接可以转到wiki:点击打开链接很明显,不管egg1怎么丢,egg2肯定得线性得丢。我们假设egg1每次丢10层,即按10f, 20f, 30f, 40f, 50f, 60f, 70f, 80f, 90f, 100f。则,如

2015-08-18 19:40:53 1226

原创 位操作总结

有一类题是位操作,但是感觉在面试中,很少有这种题,毕竟不需要那么细的操作,感觉位操作在汇编和C语言关系比较大,比较偏底层。但是有时候用位操作往往得到意想不到的效果。http://graphics.stanford.edu/~seander/bithacks.html关于常见的为操作可以看这链接,将了好多方法,现将比较常见的整理一下。一、位的基本操作基本操作主要有六种,与、或、异或、

2015-08-18 15:41:22 1330

原创 LeetCode-Single NumberI II III

I)Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi

2015-08-17 20:30:34 907

原创 剑指offer-二叉搜索树与双向链表

输入一颗二叉搜索树,将该二叉搜索树转换成一个排序的双向两步。空间复杂度为O(1).最笨的方法就是中序遍历放在一个数组或链表中,再次遍历串联起来。但是要求空间复杂度为O(1),就没办法这么做了,这时候可以参考这个解法。http://blog.csdn.net/my_jobs/article/details/47666909判断一个树是不是一颗二叉搜索树,可以模仿最后的那个方法。本题跟

2015-08-17 15:10:36 1279

原创 LeetCode-Lowest Common Ancestor of a Binary Tree 深度解析

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node

2015-08-16 18:48:04 1506

原创 LeetCode - Populating Next Right Pointers in Each Node II 及其变形题

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.

2015-08-15 18:10:11 998

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

2015-08-15 16:11:26 1315

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

2015-08-15 16:10:26 1039

原创 LeetCode-Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.没什么可说的,直接上代码:

2015-08-14 21:16:15 644

原创 LeetCode-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}, 3 / \ 9 20

2015-08-14 17:28:44 822

原创 LeetCode-Balanced Binary Tree

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 never diffe

2015-08-14 16:53:10 715

原创 LeetCode-Maximum/Minimum Depth of Binary Tree

iven a binary tree, find its maximum/minimum depth.The maximum/minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.两个很相似的题,但是解法完全不怎么

2015-08-14 15:39:02 738

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

2015-08-13 20:57:10 660

原创 LeetCode-Implement Queue using Stacks

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 element.empt

2015-08-13 20:08:16 1013

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

2015-08-13 15:29:44 840

原创 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.此题是Majority Element的继续,关于此题可以移步至Majority Elem

2015-08-06 11:03:29 1197

原创 LeetCode-Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O

2015-07-31 10:18:18 848

原创 Remove Element(删除重复元素,循环删除2个及2个以上元素)

Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.时间复

2015-04-22 22:04:20 1143

原创 zookeeper的安装,搭建

ZooKeeper的安装模式分为三种,分别为:单机模式(stand-alone)、集群模式(replicated mode)和集群伪分布模式。ZooKeeper 单机模式的安装相对比较简单,如果第一次接触ZooKeeper的话,建议安装ZooKeeper单机模式或者集群伪分布模式。安装ZooKeeper的前提是必须安装JDK,版本6以上,具体安装见 http://blog.csdn.net

2015-04-16 16:13:54 918

原创 linux下安装jdk

第一种,用linux自带的yum工具,比如 yum search jdk。进行搜索jdk软件,之后直接安装,比如java-1.7.0-openjdk.x86_64第二种方式就是自己去官网下载安装。具体如下:1.官网下面所需版本,比如32位,或者64位。2.选择安装位置,比如/usr/jdk/。如果没有,自己可以新建3.将下载的文件解压,比如:tar -zxvf jdk-7u45-l

2015-04-16 09:41:29 1080

原创 Search a 2D Matrix(在二维数组中查找)

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each

2015-03-22 18:58:50 1234

原创 LeetCode-Anagrams

Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.首先理解一下题,什么是anagrams,就是,在String1里出现过的字符在String2里也都出现过,并且个数是一样的。比如 “dog” , “gdo

2015-03-15 16:28:32 605

原创 LeetCode-Word Break II

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"

2015-03-13 20:56:46 1013

原创 String, StringBuffer, StringBuilder比较

字符串操作在编程中的用处是非常大的,而在编程时选择哪个字符串操作呢?我们在这里比较三个,主要区别如下:String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全)插入删除修改的速度比较(在一般情况下,不具有普世性)操作字符串速度: StringBuilder > StringBuffer > StringB

2015-03-12 20:53:04 957

空空如也

空空如也

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

TA关注的人

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