Skip to content

Commit e1a2b95

Browse files
committed
一刷744
1 parent 958c3ee commit e1a2b95

File tree

7 files changed

+64
-11
lines changed

7 files changed

+64
-11
lines changed

README.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5233,14 +5233,14 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
52335233
//|{doc_base_url}/0743-network-delay-time.adoc[题解]
52345234
//|Medium
52355235
//|
5236-
//
5237-
//|{counter:codes}
5238-
//|{leetcode_base_url}/find-smallest-letter-greater-than-target/[744. Find Smallest Letter Greater Than Target^]
5239-
//|{source_base_url}/_0744_FindSmallestLetterGreaterThanTarget.java[Java]
5240-
//|{doc_base_url}/0744-find-smallest-letter-greater-than-target.adoc[题解]
5241-
//|Easy
5242-
//|
5243-
//
5236+
5237+
|{counter:codes}
5238+
|{leetcode_base_url}/find-smallest-letter-greater-than-target/[744. Find Smallest Letter Greater Than Target^]
5239+
|{source_base_url}/_0744_FindSmallestLetterGreaterThanTarget.java[Java]
5240+
|{doc_base_url}/0744-find-smallest-letter-greater-than-target.adoc[题解]
5241+
|Easy
5242+
|
5243+
52445244
//|{counter:codes}
52455245
//|{leetcode_base_url}/prefix-and-suffix-search/[745. Prefix and Suffix Search^]
52465246
//|{source_base_url}/_0745_PrefixAndSuffixSearch.java[Java]

docs/0000-00-note.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
. 前缀和
1111
.. xref:0523-continuous-subarray-sum.adoc[523. Continuous Subarray Sum]
1212
. 树的 Morris 遍历
13-
.. TODO: 基于 Morris 遍历的中序排列已经掌握,前序,尤其是后续还需要加强。
13+
.. 基于 Morris 遍历的中序排列已经掌握,前序,尤其是后续还需要加强。
14+
. 二分搜索怎样可以确定地取左右端点?
1415

1516
image::images/quick-sort-01.gif[{image_attr}]
1617

docs/0000-01-modified-binary-search.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55

66
对于一组满足上升排列的数集来说,这种模式的步骤是这样的:
77

8-
. 首先,算出左右端点的中点。最简单的方式是这样的:middle = (start + end) / 2。但这种计算方式有不小的概率会出现整数越界。因此一般都推荐另外这种写法:middle = start + (end start) / 2
8+
. 首先,算出左右端点的中点。最简单的方式是这样的: latexmath:[middle = (start + end) / 2]。但这种计算方式有不小的概率会出现整数越界。因此一般都推荐另外这种写法: latexmath:[middle = start + (end - start) / 2].
99
. 如果要找的目标改好和中点所在的数值相等,我们返回中点的下标就行
1010
. 如果目标不等的话:我们就有两种移动方式了如果目标比中点在的值小(key < arr[middle]):将下一步搜索空间放到左边(end = middle - 1)
1111
. 如果比中点的值大,则继续在右边搜索,丢弃左边:left = middle + 1
1212

13+
== 疑问点
14+
15+
. 二分搜索怎样可以确定地取左右端点?
16+
1317
== 经典题目
1418

1519
. xref:0033-search-in-rotated-sorted-array.adoc[33. Search in Rotated Sorted Array]

docs/0744-find-smallest-letter-greater-than-target.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,24 @@ target = "k"
5656

5757

5858
[[src-0744]]
59+
[tabs]
60+
====
61+
一刷::
62+
+
63+
--
5964
[{java_src_attr}]
6065
----
6166
include::{sourcedir}/_0744_FindSmallestLetterGreaterThanTarget.java[tag=answer]
6267
----
68+
--
69+
70+
// 二刷::
71+
// +
72+
// --
73+
// [{java_src_attr}]
74+
// ----
75+
// include::{sourcedir}/_0744_FindSmallestLetterGreaterThanTarget_2.java[tag=answer]
76+
// ----
77+
// --
78+
====
6379

docs/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ include::0739-daily-temperatures.adoc[leveloffset=+1]
15621562

15631563
// include::0743-network-delay-time.adoc[leveloffset=+1]
15641564

1565-
// include::0744-find-smallest-letter-greater-than-target.adoc[leveloffset=+1]
1565+
include::0744-find-smallest-letter-greater-than-target.adoc[leveloffset=+1]
15661566

15671567
// include::0745-prefix-and-suffix-search.adoc[leveloffset=+1]
15681568

logbook/202406.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@
404404
|{doc_base_url}/0870-advantage-shuffle.adoc[题解]
405405
|双指针+优先队列(排序)
406406

407+
|{counter:codes}
408+
|{leetcode_base_url}/find-smallest-letter-greater-than-target/[744. Find Smallest Letter Greater Than Target^]
409+
|{doc_base_url}/0744-find-smallest-letter-greater-than-target.adoc[题解]
410+
|二分查找取左右端点是一个怎样的套路?
411+
407412
|===
408413

409414
截止目前,本轮练习一共完成 {codes} 道题。
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.diguage.algo.leetcode;
2+
3+
public class _0744_FindSmallestLetterGreaterThanTarget {
4+
// tag::answer[]
5+
6+
/**
7+
* @author D瓜哥 · https://www.diguage.com
8+
* @since 2024-08-23 17:04:36
9+
*/
10+
public char nextGreatestLetter(char[] letters, char target) {
11+
int length = letters.length;
12+
if (target >= letters[length - 1]) {
13+
return letters[0];
14+
}
15+
int left = 0, right = length - 1;
16+
while (left < right) {
17+
int mid = left + (right - left) / 2;
18+
if (target < letters[mid]) {
19+
right = mid;
20+
} else {
21+
left = mid + 1;
22+
}
23+
}
24+
return letters[left];
25+
}
26+
// end::answer[]
27+
}

0 commit comments

Comments
 (0)