当前位置:网站首页>2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
2022-06-24 15:55:00 【Fuda scaffold constructor's daily question】
2021-05-01: Given an ordered array arr, The representative is located in X The point on the axis . Give a positive number K, Represents the length of the rope . Return to the maximum number of points in the rope ? Even if the edge of the rope covers the point, it is covered .
Fuda answer 2021-05-01:
The sliding window . The window will only become larger or unchanged , It doesn't get smaller . Subtract the left pointer position from the last right pointer position , Is the length to be returned .
The code to use golang To write . The code is as follows :
package main
import "fmt"
func main() {
arr := []int{1, 4, 5, 6, 9, 10, 12, 17}
ret := maxPoint(arr, 4)
fmt.Println(ret)
}
func maxPoint(arr []int, num int) int {
arrLen := len(arr)
L := 0
R := 0
for R < arrLen {
if arr[R]-arr[L] > num {
L++
}
R++
}
return R - L
}The results are as follows :
边栏推荐
- 运营商5G用户渗透远远比4G慢,5G的普及还得看中国广电
- My network relationship with "apifox"
- Mysql之Binlog
- [my advanced OpenGL learning journey] learning notes of OpenGL coordinate system
- 【Prometheus】6. Prometheus and kubernetes (incomplete)
- Most common usage of vim editor
- 安裝ImageMagick7.1庫以及php的Imagick擴展
- Install the imagemagick7.1 library and the imageick extension for PHP
- Special topic of IM code scanning login Technology (III): easy to understand. A detailed principle of IM code scanning login function is enough
- 2021-04-25: given an array arr and a positive number m, the
猜你喜欢
![[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction](/img/32/720ffa63a90cd5d37460face3fde38.png)
[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction
![[my advanced OpenGL learning journey] learning notes of OpenGL coordinate system](/img/21/48802245fea2921fd5e4a9a2d9ad18.jpg)
[my advanced OpenGL learning journey] learning notes of OpenGL coordinate system

My network relationship with "apifox"

还在担心漏测吗?快来使用jacoco统计下代码覆盖率

存在安全隐患 部分冒险家混动版将召回

The catch-up of domestic chips has scared Qualcomm, the leader of mobile phone chips in the United States, and made moves to cope with the competition

Solution of intelligent all in one machine in expressway service area

Here comes Wi Fi 7. How strong is it?

【C语言刷题——Leetcode12道题】带你起飞,飞进垃圾堆

nifi从入门到实战(保姆级教程)——环境篇
随机推荐
国产最长寿的热销手机,苹果也不是对手,总算让国产手机找回面子
Why is the blackmail virus that shut down half of America's energy system terrible? Interpretation of authoritative reports
存在安全隐患 部分冒险家混动版将召回
Flink Kubernetes Application部署
2021-04-25: given an array arr and a positive number m, the
Detailed explanation of estab of Stata regression table output
From practical teaching to competition exercise, Tencent experts personally teach Ti-One platform operation strategy!
Industry cases of successful digital transformation
Leetcode 139. Mot break word Split (medium)
Most common usage of vim editor
Very exciting! 12000 words summarized the theory of network technology, reviewing the old and learning the new
MongoDB入門實戰教程:學習總結目錄
【云原生 | Kubernetes篇】Kubernetes基础入门(三)
great! The novel website project is completely open source
QTreeWidget作为单例模式以dll返回的两个问题
Solution of intelligent all in one machine in expressway service area
Istio practical skill: hide the automatically added server header
10 hands-free idea plug-ins. These codes do not need to be written (the second bullet)
运营商5G用户渗透远远比4G慢,5G的普及还得看中国广电
Jenkins 镜像无法更新插件中心的3种解决方法