Exercise1.1.22
来源:互联网 发布:温州动车 知乎 编辑:程序博客网 时间:2024/06/07 01:08
package chapterone;public class Exercise1_1_22 { public static int rank(int key, int[] array) { return rank(key, array, 0, array.length - 1, 0); } public static int rank(int key, int[] array, int low, int high, int indent) { if (low > high) { return -1; } int mid = (low + high) / 2; System.out.println(repeat(4 * indent, ' ') + low + high); if (key > array[mid]) { return rank(key, array, mid + 1, high, ++indent); } else if (key < array[mid]) { return rank(key, array, low, mid - 1, ++indent); } else { return mid; } } public static String repeat(int n, char c) { String s = ""; for (int i = 0; i < n; i++) { s += c; } return s; } public static void main(String[] args) { int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; System.out.println(rank(3, array)); }}
0 0
- Exercise1.1.22
- exercise1
- SSD3-exercise1
- SSD5 exercise1
- exercise1-17
- exercise1-19
- exercise1-16
- exercise1-18
- python exercise1
- 卡耐基 ssd6 exercise1
- Icarnegie SSD4 Exercise1 Answer
- 分支选择结构Exercise1
- SSD6 exercise1 解题思路
- SSD6 Exercise1 深入分析
- Exercise1.1.29 等值键
- 【UFLDL-exercise1-Sparse Autoencoder】
- Exercise1:第一个Python程序
- MIT-JOS-lab1-exercise1&&2
- startActivityForResult、onActivityResult对应的A与B的Activity的生命周期
- [Leetcode] 1.Two Sum @python
- iOS_视图控制对象生命周期以及区别和用途
- nodejs Tips3
- 精通Jquery之一
- Exercise1.1.22
- JQM写的手机web简单例子
- Volley拓展框架——Netroid,以及与Volley的差异
- 教你基带N9008ZMUDNB1 锁定2G /E 网 [转]
- Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on di
- POJ【1789】 -- Truck History
- Psot ,get,中文乱码问题(不知道可否解决数据库的存储读取乱码)
- Python 版桶排序
- Linux系统(Ubuntu)下,MPI的安装与配置