-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.py
More file actions
61 lines (47 loc) · 1.51 KB
/
test3.py
File metadata and controls
61 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
typedef struct {
int startAddr;
int endAddr;
} IoRecord;
// 注意:返回的数组必须在函数内调用malloc进行内存分配,由框架代码调用free进行内存释放。
// 返回的数组长度存在 *returnValSize 中。
static IoRecord *IoMerge(int sectorSize, const IoRecord *opArray, size_t opArraySize, size_t *returnValSize)
{
*returnValSize = 0;
return NULL;
}
[x1, y1] [x2, y2]
a b
1. 交叉
2. 不交叉
交叉: ab位置不确定
1. y1 >= x2
y2 >= x1
y1 i -> x2
intertvals = [a,b,c]
a.start
a[0]a[1]
32
[[0, 30], [10, 33], [130, 150], [151, 158], [60, 100], [130, 150], [20, 50]]
"""
class Solution:
def longestSubarray(self, nums: List[int], limit: int) -> int:
n = len(nums)
max_to_min, min_to_max = deque(), deque()
left = right = result = 0
while right < n:
while max_to_min and max_to_min[-1] < nums[right]:
max_to_min.pop()
while min_to_max and min_to_max[-1] > nums[right]:
min_to_max.pop()
max_to_min.append(nums[right])
min_to_max.append(nums[right])
while max_to_min and min_to_max and max_to_min[0] - min_to_max[0] > limit:
if nums[left] == min_to_max[0]:
min_to_max.popleft()
if nums[left] == max_to_min[0]:
max_to_min.popleft()
left += 1
result = max(result, right - left + 1)
right += 1
return result