题目: 给定一个数组,求如果排序之后,相邻两数的最大差值,要求时间复杂度为O(N),且要求不能用非基于比较的排序 public static int maxGap(int nums[]) { if (nums == null || nums.length < 2) { return 0; } int len = nums.length; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for (int i = 0; i < l
给定一个数列a1,a2,a3,...,an和m个三元组表示的查询,对于每个查询(i,j,k),输出ai,ai+1,...,aj的升序排列中第k个数. #include <iostream> using namespace std; #define SIZE 20 #define M 3 typedef struct Elem { int i, j; int k; } ELEM; /* 表示一个元素的三元组结构 */ int getMedian(int* arr, int low, int hi
题目:给定一个字符串s,一个整数numRows, 将字符串s按照竖Z的方式排列,然后输出结果: 举例:String s = "PAYPALISHIRING"; 排列后为: P A H N A P L S I I G Y I RString convert(String s, int 3) 结果为"PAHNAPLSIIGYIR" 解题思路: 1. 由于每一行到底有多少个字母是不确定的,因此每行使用ArrayList来保存字母:如5,6,7行代码所示: 2. 遍历字