当前位置:网站首页>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 :
边栏推荐
- CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
- Why is the blackmail virus that shut down half of America's energy system terrible? Interpretation of authoritative reports
- [C language questions -- leetcode 12 questions] take you off and fly into the garbage
- [download attached] installation and simple use of Chinese version of awvs
- April 23, 2021: there are n cities in the TSP problem, and there is a distance between any two cities
- Recommend several super practical data analysis tools
- I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15
- 2021-05-04: given a non negative integer C, you need to judge whether there are two integers a and B, so that a*a+b*b=c.
- MySQL binlog
- leetcode 139. Word Break 单词拆分(中等)
猜你喜欢

【云原生 | Kubernetes篇】Kubernetes基础入门(三)

一文理解OpenStack网络

MongoDB入門實戰教程:學習總結目錄

Remote connection raspberry pie in VNC Viewer Mode

Nifi from introduction to practice (nanny level tutorial) - environment

存在安全隐患 路虎召回部分混动揽运

Still worried about missing measurements? Let's use Jacobo to calculate the code coverage

I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15

熬夜整理出的软件测试【高频】面试题大全(2022最新)

Solution of intelligent all in one machine in expressway service area
随机推荐
Decomposition of Uber dependency injection into dig source code analysis
Nature刊登量子计算重大进展:有史以来第一个量子集成电路实现
MongoDB入门实战教程:学习总结目录
FreeRTOS新建任务不执行问题解决办法
Two problems of qtreewidget returning as DLL in singleton mode
Reference to junit5 test framework in gradle
Nifi from introduction to practice (nanny level tutorial) - environment
推荐几款超级实用的数据分析利器
微信公众号调试与Natapp环境搭建
MongoDB入門實戰教程:學習總結目錄
nifi从入门到实战(保姆级教程)——环境篇
Remain true to our original aspiration
SIGGRAPH 2022 | 真实还原手部肌肉,数字人双手这次有了骨骼、肌肉、皮肤
一文详解JackSon配置信息
Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]
Industry cases of successful digital transformation
Mongodb Getting started Practical Tutoriel: Learning Summary Table des matières
Is it safe for futures companies to open accounts
Build go command line program tool chain