摘要:
设a[],b[]都是长为数百万的数组 int[] t = a; a=b; b = t; 这段代码会将他们交换。它的效率不可能再高了, 因为它交换的是引用,而不是数百万个元素。 例子如下: import edu.princeton.cs.algs4.StdOut; public class No_1_ 阅读全文
摘要:
public class Binarysearch { public static int rank(int key,int[] a) { return rank(key,a,0,a.length-1); } public static int rank(int key,int[] a,int lo 阅读全文
摘要:
import edu.princeton.cs.algs4.*; public class No_1_1_13 { public static void main(String[] args) { int m=4; int n=3; int [][] a = new int[m][n]; for(i 阅读全文
摘要:
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symme 阅读全文
摘要:
Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as: h d e l l r 阅读全文
摘要:
Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 1 阅读全文
摘要:
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, wher 阅读全文
摘要:
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number 阅读全文
摘要:
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years 阅读全文
摘要:
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the 阅读全文
摘要:
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file contains one t 阅读全文
摘要:
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number 阅读全文
摘要:
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to ou 阅读全文