mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Format the Java codes with the Reat Hat extension.
This commit is contained in:
@@ -42,11 +42,11 @@ public class binary_search {
|
||||
// 未找到目标元素,返回 -1
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int target = 6;
|
||||
int[] nums = { 1, 3, 6, 8, 12, 15, 23, 67, 70, 92 };
|
||||
|
||||
|
||||
/* 二分查找(双闭区间) */
|
||||
int index = binarySearch(nums, target);
|
||||
System.out.println("目标元素 6 的索引 = " + index);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class hashing_search {
|
||||
// 初始化哈希表
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
for (int i = 0; i < nums.length; i++) {
|
||||
map.put(nums[i], i); // key: 元素,value: 索引
|
||||
map.put(nums[i], i); // key: 元素,value: 索引
|
||||
}
|
||||
int index = hashingSearchArray(map, target);
|
||||
System.out.println("目标元素 3 的索引 = " + index);
|
||||
@@ -42,7 +42,7 @@ public class hashing_search {
|
||||
// 初始化哈希表
|
||||
Map<Integer, ListNode> map1 = new HashMap<>();
|
||||
while (head != null) {
|
||||
map1.put(head.val, head); // key: 节点值,value: 节点
|
||||
map1.put(head.val, head); // key: 节点值,value: 节点
|
||||
head = head.next;
|
||||
}
|
||||
ListNode node = hashingSearchLinkedList(map1, target);
|
||||
|
||||
Reference in New Issue
Block a user