CC150 - 11.3】的更多相关文章

Question: Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element. package POJ; public class Main { /** * * 11.6 Given an M x N matrix in which each row and each column is sorted in * as…
Question: Given a sorted array of strings which is interspersed with empty strings, write a method to find the location of a given string. package POJ; public class Main { /** * * 11.5 Given a sorted array of strings which is interspersed with empty…
Question: Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. package POJ; import java.util.Arrays;…
Question: Write a method to sort an array of strings so that all the anagrams are next to each other. package POJ; import java.util.Arrays; import java.util.Comparator; import java.util.Hashtable; import java.util.LinkedList; import java.util.List; p…
Question: You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B.Write a method to merge B into A in sorted order. package POJ; public class Main { /** * * 11.1 You are given two sorted arrays, A and B, where…
/*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : localhost:3306Source Database : ben500_info Target Server Type : MYSQLTarget Server Version : 50136File Encoding : 65001 Date: 2013-07-11 10:07:33*/ SET…
思路:比较easy.就是借助hashset让他有序然后就能够比较节省时间了. 答案: public static int[] getRankOfNumber(int[] a, int n){ int[] res = new int[n]; HashSet<Integer> hash = new HashSet(); for(int i = 0; i < n;i++){ int num = 0; for(int tmp : hash){ if(tmp <= a[i]){ num++;…
1,牛客网第一题:这其实跟找最长递增子序列是一个东西.注意的地方是,返回的是最大的dp,而不是dp[N-1]. 答案: public static int getHeight(int[] men, int n) { // write code here int res = 0; int[] dp = new int[n]; dp[0] = 1; for(int i =1;i <n;i++){ int max = 0; for(int j =0;j < i;j++){ if(men[j] <…
思路,一旦提到查找就要想到二分查找. public static int[] findElement(int[][] a, int n, int m, int key) { // write code here int[] res = new int[2]; for(int i = 0;i < n;i++){ int left = 0; int right = m - 1; while(left <= right){ int mid = (left + right) / 2; if(key &…
注意,1,"" 和 " ".是不同的,空字符串指的是"": 2,注意String的compareTo.小于是指<0.并不是==-1: 仔细观察代码中注释掉的那一行错在哪里. import java.util.*; public class Finder { public static int findString(String[] a,int n, String key){ int left = 0; int right = a.lengt…