当前位置:网站首页>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 :
边栏推荐
- Special topic of IM code scanning login Technology (III): easy to understand. A detailed principle of IM code scanning login function is enough
- Linux record -4.22 MySQL 5.37 installation (supplementary)
- [application recommendation] the hands-on experience and model selection suggestions of apifox & apipost in the recent fire
- Nifi from introduction to practice (nanny level tutorial) - environment
- CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
- Jenkins的便捷式安装
- 安装ImageMagick7.1库以及php的Imagick扩展
- Easy installation of Jenkins
- Most common usage of vim editor
- Is it safe for futures companies to open accounts
猜你喜欢
【面试高频题】难度 3/5,可直接构造的序列 DP 题
Here comes Wi Fi 7. How strong is it?
MySQL binlog
Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
Linux record -4.22 MySQL 5.37 installation (supplementary)
60 个神级 VS Code 插件!!
存在安全隐患 部分冒险家混动版将召回
[C language questions -- leetcode 12 questions] take you off and fly into the garbage
Nifi from introduction to practice (nanny level tutorial) - environment
随机推荐
Database tools in intelij can connect but cannot display schema, tables
60 个神级 VS Code 插件!!
Remain true to our original aspiration
Hardware security threats of cloud infrastructure
存在安全隐患 路虎召回部分混动揽运
"Industry foresight" future development trend of intelligent security monitoring industry
Here comes Wi Fi 7. How strong is it?
Ascinema with asciicast2gif for efficient command line terminal recording
国产芯片的赶超,让美国手机芯片龙头高通害怕了,出招应对竞争
PHP export data as excel table
安装ImageMagick7.1库以及php的Imagick扩展
Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15
MySQL development specification
Logging is not as simple as you think
Build go command line program tool chain
Understanding openstack network
Flink Kubernetes Application部署
April 23, 2021: there are n cities in the TSP problem, and there is a distance between any two cities
打破内存墙的新利器成行业“热搜”!持久内存让打工人也能玩转海量数据+高维模型