java
文章平均质量分 67
urgemule
hash(x) == x
展开
-
立此存照(5)label标签与break和continue
public class Test{ public static void main(String[] args){ int[][] arr = {{1,2,3,4},{5,6,7, 8},{9, 10, 11, 12}}; new Test().dblloop1(arr); new Test().dblloop2(arr); new Test().dblloop3(arr);原创 2014-08-12 20:22:07 · 549 阅读 · 0 评论 -
Cracking coding interview(4.3)给定一个排好序的数组创建最小高度的二叉树
4.3 Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.原创 2014-08-03 11:32:28 · 724 阅读 · 0 评论 -
Cracking coding interview(3.1)用一个数组实现3个堆栈
3.1 Describe how you could use a single array to implement three stacks.原创 2014-07-29 10:08:05 · 614 阅读 · 0 评论 -
Cracking coding interview(2.2)返回单向链表的倒数第n个节点
2.2 Implement an algorithm to find the nth to last element of a singly linked list.原创 2014-07-26 21:31:55 · 476 阅读 · 0 评论 -
Cracking coding interview(2.1)去除LinkedList中的重复元素
2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?原创 2014-07-26 20:08:17 · 670 阅读 · 0 评论 -
Cracking coding interview(2.4)单向链表相加
2.4 You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a func原创 2014-07-28 13:50:00 · 496 阅读 · 0 评论 -
BinaryTree(0).关于平衡二叉树的实现
1.平衡二叉树定义:平衡二叉树是: || 每个节点的左右子树高度差不大于1的非空树>。原创 2014-08-02 10:54:50 · 438 阅读 · 0 评论 -
Cracking coding interview(4.1)二叉树平衡问题
4.1 Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by more原创 2014-08-01 13:40:30 · 572 阅读 · 0 评论 -
Cracking coding interview(2.3)灵活删除LinkedList中间元素
class Node{ int data; Node next; public Node(int data, Node next){ this.data = data; this.next = next; }}public class Solution{ //middle is not my problem //from head to mid public static原创 2014-07-26 23:07:01 · 492 阅读 · 0 评论 -
Cracking coding interview(4.4) 二叉树水平遍历
4.4 Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists).原创 2014-08-03 14:08:23 · 740 阅读 · 0 评论 -
Cracking coding interview (4.5)二叉树按中序遍历次序返回某节点下一个节点
4.5 Write an algorithm to find the ‘next’ node (e.g., in-order successor) of a given node in a binary search tree where each node has a link to its parent.原创 2014-08-03 19:16:05 · 638 阅读 · 0 评论 -
Cracking coding interview(2.5) 查找环形链表的环形起点
第二种方法原创 2014-07-28 19:48:14 · 466 阅读 · 0 评论 -
知其然(3)*.java文件中可以包含多个类,但最多只能有一个类,其修饰符为public
1.*.java文件中可以包含多个类,但最多只能有一个类的public原创 2014-08-11 21:09:42 · 2298 阅读 · 1 评论 -
立此存照(4)java中的&和&&用法
public class Test{ public static void main(String[] args){ //均可表示逻辑与"and" System.out.println("true & false = "+(true & false)); System.out.println("true && false = "+(true && false)); System.原创 2014-08-11 22:36:27 · 760 阅读 · 0 评论 -
Cracking coding interview(4.2)有向图判断任意2点之间是否有一条有向路径
4.2 Given a directed graph, design an algorithm to find out whether there is a route between two nodes.原创 2014-08-03 10:02:11 · 676 阅读 · 0 评论 -
Cracking coding interview(3.5)使用2个堆栈实现一个队列
3.5 Implement a MyQueue class which implements a queue using two stacks.import java.util.Stack;class MyQueue{ private Stack s1 = new Stack(); private Stack s2 = new Stack(); //time complexi原创 2014-07-31 15:45:07 · 519 阅读 · 0 评论 -
Cracking coding interview(3.6)堆栈排序
3.6 Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write this p原创 2014-07-31 16:59:13 · 483 阅读 · 0 评论 -
Cracking coding interview(3.3)实现堆栈集合和popAt函数实现
copyright:3.3 Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some thresh原创 2014-07-31 09:54:45 · 651 阅读 · 0 评论 -
Cracking coding interview(3.4)汉诺塔递归实现(一)
. CareerCup com 1183.4 In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending原创 2014-07-31 14:52:19 · 763 阅读 · 0 评论 -
Cracking coding interview(3.2)堆栈实现常量复杂度的min函数
3.2 How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time.原创 2014-07-29 16:13:26 · 734 阅读 · 0 评论 -
leetcode(十三)Add Two Numbers
copyright:leetcodeYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two原创 2014-07-24 13:41:55 · 501 阅读 · 0 评论 -
Cracking coding interview(1.3)去掉字符串中重复字符
1.3 Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is原创 2014-07-26 17:39:14 · 516 阅读 · 0 评论 -
leetcode之八Next Permutation
copyright:leetcodeImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearr原创 2014-07-22 19:56:15 · 433 阅读 · 0 评论 -
Leetcode之六Binary Tree Level Order Traversal
copyright:leetcode原创 2014-07-21 22:33:41 · 415 阅读 · 0 评论 -
Leetcode之七Binary Tree Level Order Traversal II
copyright:leetcode原创 2014-07-21 22:38:39 · 374 阅读 · 0 评论 -
Leetcode之四Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,2,原创 2014-07-19 21:15:32 · 456 阅读 · 0 评论 -
Leetcode之五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原创 2014-07-20 10:38:34 · 381 阅读 · 0 评论 -
Leetcode之三Max Points on a Line
copyrightGiven n points on a 2D plane, find the maximum number of points that lie on the same straight line.原创 2014-07-18 17:15:24 · 372 阅读 · 0 评论 -
leetcode之Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-07-18 11:00:16 · 425 阅读 · 0 评论 -
java FileOutputStream流文件创建注意事项
String input="1234";DataOutputStream out=new DataOutputStream(new FileOutputStream("passwd/input.dat")); out.writeUTF(input); //若要input.dat 文件创建成功,必须存在先在当前目录下创建passwd目录原创 2014-06-29 11:37:18 · 2245 阅读 · 0 评论 -
leetcode之九Reverse Integer
copyright:leetcode原创 2014-07-22 20:39:32 · 430 阅读 · 0 评论 -
leetcode之十Maximum Depth of Binary Tree
copyright:leetcodeGiven 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.原创 2014-07-23 09:20:59 · 280 阅读 · 0 评论 -
leetcode(十一)Copy List with Random Pointer
copyright:leetcode原创 2014-07-23 10:40:48 · 419 阅读 · 0 评论 -
Cracking coding interview(1.7) 设置某个位置为零的矩阵对应行列均为0
1.7 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.原创 2014-07-26 17:14:13 · 418 阅读 · 0 评论 -
Cracking coding iterview(1.6)Rotate NXN Matrix
1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?原创 2014-07-26 13:44:39 · 469 阅读 · 0 评论 -
Cracking coding interview(1.1)给定String判断是否unique
1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?原创 2014-07-25 19:15:18 · 728 阅读 · 0 评论 -
leetcode(十五)Merge Sorted Array
copyright:leetcodeGiven two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to原创 2014-07-24 19:19:47 · 378 阅读 · 0 评论 -
leetcode(十六)Single Number
copyright:leetcode原创 2014-07-24 20:16:26 · 595 阅读 · 0 评论 -
leetcode(十二)Binary Tree Inorder Traversal
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { publi原创 2014-07-24 08:59:34 · 331 阅读 · 0 评论 -
leetcode(十二)Binary Tree Inorder Traversal
copyright:leetcodeGiven 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].原创 2014-07-23 22:38:02 · 326 阅读 · 0 评论