自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Yuwen's Hero

专注面试题, 博客 http://blog.csdn.net/beiyeqingteng 的镜像站

  • 博客(20)
  • 收藏
  • 关注

原创 rotate matrix

Given an image represented by a matrix, write a method to rotate the image by 90 degrees. Can you do this in place?static void rotateClockwise(int[][] matrix) { int length = matrix.length - 1; for

2013-02-26 12:18:29 1259

原创 O变X

给你一个n * n 的二维char数组 内部存的是 'X' 和 'O',形式如下X  X  X  X  XX  O  O  O  XX  X  O  O  XX  X  X  O  XX  O  X  X  X编写一个函数将被'X'包围的'O'统统变成'X'。 比如下标为 (1,1) (1,2) (1,3) (2,2) (2,3) (3,3)的'O'需要被变成'X',而下标

2013-02-24 12:45:11 770

原创 Group of 1s in a Matrix

Given a matrix with 1s and 0s, please find the number of groups of 1s. A group is defined by horizontally or vertically adjacent 1s. For example, there are four groups of 1s in figure below.Anal

2013-02-24 04:48:33 541

原创 Sum of a tree

You are given a tree, and the nodes in the tree may have more than two child nodes, calculate the sum of the tree where the root to the leaf is considered as a number.public class TreeSum { priva

2013-02-22 07:40:36 553

原创 print out the path from one node to another in binary tree

Question:You are given one binary tree, find the path from one node to another.public static LinkedList printPath(Node root, Node n1, Node n2) { Node temp = root; LinkedList rootToN1 = new Lin

2013-02-18 11:33:56 731

原创 把一个字符串转成double类型的数

问题:给一个字符串,比如“-12.05”,把它转成相应的double类型的数。分析:在进行转换的时候,要注意以下问题:1. 该字符串是否为空2. 是否该字符串含有符号;3. 该字符串内是否有非法字符;4. 小数点的位置;备注:本文不考虑溢出的情况。代码如下:/* * allowed format: -.4; +.4; -1.2; 2.5;35.;+35.

2013-02-18 01:40:38 10330 1

原创 二叉树非递归遍历

这里写出三种儿叉查询树遍历的非递归写法,非常有意思。preorder:先打印root,再left,最后right。 public static void BSTPreorderTraverse(Node node) { if (node == null) { return; } Stack s = new Stack(); s.

2013-02-16 07:15:44 980

原创 Word Ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediat

2013-02-14 13:32:23 4693

原创 huffman编码及解码实现

Huffman编码就是利用每个字符出现频率的不一致,用长短不一的0、1字节来表示不同的字符以减少总数据大小。 假设我们有一包含10000个字符的文件,这些字 符仅由6个不同的字符组成,就设这6个字符分别为“abcdef”,下面的表给出了 这6个字符在整个文件中的占比,和两种不同的编码方式。abcdefFrequency (in t

2013-02-13 06:52:01 6399 1

原创 JAVA PriorityQueue应用实例

PriorityQueue这种数据结构支持按照优先级取出里面的元素。这是和其它常用数据结构,比如 ArrayList, Queue, Stack等最大的区别。因为要支持优先级,而heap具有类似的结构,所以,PriorityQueue一般都是基于HEAP实现的。(也可以用其它数据结构实现,但是各种复杂度会有不同。)基于HEAP实现的PriorityQueue复杂度分析:add(E e):

2013-02-13 01:31:44 11254 2

转载 OOD面试题

面向对象设计如何应对面向对象设计的问题非常重要,它能反映出面试者的代码质量。若是对此类问题支支吾吾,面试多半就凶多吉少了。应付面试中的含糊不清面向对象设计的问题经常是有意含糊的,以此测试你是否会做假设,或者考验你是否会进一步地询问,以明确需求。否则当面对模棱两可的约束时,你又如何设计一个类呢?抛出你的问题来消除这些含糊,然后再设计类来处理剩余的含糊之处。面向

2013-02-12 23:46:41 9867

原创 在数组里查找这样的数,它大于等于左侧所有数,小于等于右侧所有数

问题:一个int数组, 比如 array[],里面数据无任何限制,要求求出所有这样的数array[i],其左边的数都小于等于它,右边的数都大于等于它。能否只用一个额外数组和少量其它空间实现。分析:最原始的方法是检查每一个数 array[i] ,看是否左边的数都小于等于它,右边的数都大于等于它。这样做的话,要找出所有这样的数,时间复杂度为O(N^2)。其实可以有更简单的方法,我们

2013-02-11 11:59:22 2444

原创 把手机键盘输入转化成短消息

手机键盘每个数字对应的字符如下:0 ---> "0";1 ---> "1";2 --- > "ABC2";3 ---> "DEF3";4 ---> "GHI4";5 ---> "JKL5";6 ---> "MNO6";7 ---> "PQRS7";8 ---> "TUV8";9 ---> "WXYZ9";* ---> 空格;# --->  断开;

2013-02-11 03:51:58 730

原创 add two numbers without using +

Question:Add two numbers without using "+".Analysis:If "+" is not allowed, we have to use the bit manipulation.  public static int add(int num1, int num2) { if (num1 == 0) return num2; int

2013-02-11 02:46:39 488

原创 evaluate a mathematical expression

Question:You are give a piece of mathematical expression, e.g., 3 * 4 + 5, return the value of that expression.public class EvaluateDeluxe { // result of applying binary operator op to two op

2013-02-07 13:53:45 876

转载 随机Set

问题:How would you define a data structure that stores a set ofvalues (i.e., a value cannot appear more than one time), and implements the following functions:add(p)--adds the value p to the setde

2013-02-05 07:38:34 751

原创 Divide Two Integers

Divide two integers without using multiplication, division and mod operator.public class Solution { public int divide(int dividend1, int divisor1) { if (divisor1 == 1) return dividend1;

2013-02-03 09:59:16 2056 1

原创 Convert a BST to a sorted doubly-linked list in-place

Convert a BST to a sorted doubly-linked list in-placepublic class Solution { static Node lastNode = null; public static void main(String[] args) { Node n1 = new Node(7); Node n2 = new No

2013-02-02 08:53:08 716

原创 array shuffling

Suppose we have an array a1, a2, ..., an, b1, b2, ..., bn. Implement an algorithm to change this array to a1, b1, a2, b2, ..., an, bn.public void shuffle(char[] arr) { if (arr == null || arr.length

2013-02-02 02:57:13 792

原创 箱子开闭问题

问题:There are 100 closed lockers in a hallway. A man begins by opening all the 100 lockers. Next, he closes every second locker. Then he goes to every third locker and closes it if it is open or open

2013-02-02 00:09:03 873

空空如也

空空如也

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

TA关注的人

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