提交 8cb968d9 编写于 作者: C CyC2018

auto commit

上级 9cf61224
......@@ -76,7 +76,7 @@
## 无限期等待(Waiting)
等待其它线程显地唤醒,否则不会被分配 CPU 时间片。
等待其它线程显地唤醒,否则不会被分配 CPU 时间片。
| 进入方法 | 退出方法 |
| --- | --- |
......@@ -794,9 +794,10 @@ public class SemaphoreExample {
try {
semaphore.acquire();
System.out.print(semaphore.availablePermits() + " ");
semaphore.release();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
semaphore.release();
}
});
}
......
......@@ -95,7 +95,7 @@
**一致性哈希**
Distributed Hash Table(DHT):对于哈希空间 0\~2<sup>n</sup>,将该哈希空间看成一个哈希环,将每个节点都配置到哈希环上。每个数据对象通过哈希取模得到哈希值之后,存放到哈希环中顺时针方向第一个大于等于该哈希值的节点上。
Distributed Hash Table(DHT):对于哈希空间 [0, 2<sup>n</sup>-1],将该哈希空间看成一个哈希环,将每个节点都配置到哈希环上。每个数据对象通过哈希取模得到哈希值之后,存放到哈希环中顺时针方向第一个大于等于该哈希值的节点上。
<div align="center"> <img src="../pics//d2d34239-e7c1-482b-b33e-3170c5943556.jpg"/> </div><br>
......
......@@ -82,7 +82,7 @@
# 2. 实现 Singleton
> [单例模式](https://github.com/CyC2018/Interview- Notebook/blob/master/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md)
> [单例模式](https://github.com/CyC2018/Interview-Notebook/blob/master/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md)
# 3. 数组中重复的数字
......@@ -1142,7 +1142,7 @@ public ListNode Merge(ListNode list1, ListNode list2) {
ListNode head = new ListNode(-1);
ListNode cur = head;
while (list1 != null && list2 != null) {
if (list1.val < list2.val) {
if (list1.val <= list2.val) {
cur.next = list1;
list1 = list1.next;
} else {
......@@ -1409,7 +1409,7 @@ public ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
## 题目描述
输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。
输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。假设输入的数组的任意两个数字都互不相同。
例如,下图是后序遍历序列 3,1,2 所对应的二叉搜索树。
......@@ -1673,36 +1673,30 @@ public ArrayList<Integer> GetLeastNumbers_Solution(int[] nums, int k) {
int kthSmallest = findKthSmallest(nums, k - 1);
ArrayList<Integer> ret = new ArrayList<>();
for (int val : nums) {
if (val <= kthSmallest && ret.size() < k) ret.add(val);
if (val <= kthSmallest && ret.size() < k) {
ret.add(val);
}
}
return ret;
}
public int findKthSmallest(int[] nums, int k) {
int l = 0;
int h = nums.length - 1;
int l = 0, h = nums.length - 1;
while (l < h) {
int j = partition(nums, l, h);
if (j < k) {
l = j + 1;
} else if (j > k) {
h = j - 1;
} else {
break;
}
if (j == k) break;
if (j > k) h = j - 1;
else l = j + 1;
}
return nums[k];
}
private int partition(int[] nums, int l, int h) {
int i = l;
int j = h + 1;
int i = l, j = h + 1;
while (true) {
while (i < h && nums[++i] < nums[l]) ;
while (j > l && nums[l] < nums[--j]) ;
if (i >= j) {
break;
}
if (i >= j) break;
swap(nums, i, j);
}
swap(nums, l, j);
......@@ -1710,9 +1704,7 @@ private int partition(int[] nums, int l, int h) {
}
private void swap(int[] nums, int i, int j) {
int t = nums[i];
nums[i] = nums[j];
nums[j] = t;
int t = nums[i]; nums[i] = nums[j]; nums[j] = t;
}
```
......@@ -1882,7 +1874,7 @@ private int getAmountOfDigit(int digit) {
}
/**
* 在 digit 位数组成的字符串中,第 index 为的
* 在 digit 位数组成的字符串中,第 index
*/
private int digitAtIndex(int index, int digit) {
int number = beginNumber(digit) + index / digit;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册