当前位置:网站首页>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 :
边栏推荐
- Decomposition of Uber dependency injection into dig source code analysis
- 【我的OpenGL学习进阶之旅】OpenGL的坐标系的学习笔记
- Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
- Crmeb multi merchant system applet authorization problem solving paste
- Install the imagemagick7.1 library and the imageick extension for PHP
- Poor remote code execution in Alien Swarm
- Precautions for using JMeter suite to build a pressure test environment
- Learning these 10 kinds of timed tasks, I'm a little floating
- Binary computing
- 【Prometheus】6. Prometheus and kubernetes (incomplete)
猜你喜欢

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

Database tools in intelij can connect but cannot display schema, tables

Why is it easy for enterprises to fail in implementing WMS warehouse management system

用 Oasis 开发一个跳一跳(一)—— 场景搭建

Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021

VNC Viewer方式的远程连接树莓派

FreeRTOS新建任务不执行问题解决办法

Using oasis to develop a hop by hop (I) -- Scene Building

Solution to the problem that FreeRTOS does not execute new tasks

日志记录真没你想的那么简单
随机推荐
great! The novel website project is completely open source
Rush for IPO, Hello, I'm in a hurry
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
The equipment is connected to the easycvr platform through the national standard gb28181. How to solve the problem of disconnection?
Vim编辑器的最常用的用法
MySQL 开发规范
推荐几款超级实用的数据分析利器
CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
Linux record -4.22 MySQL 5.37 installation (supplementary)
60 divine vs Code plug-ins!!
Instruction document for online written examination assistance of smart side school recruitment
存在安全隐患 部分冒险家混动版将召回
在Gradle 中对Junit5 测试框架引用
Using alicloud RDS for SQL Server Performance insight to optimize database load - first understanding of performance insight
From practical teaching to competition exercise, Tencent experts personally teach Ti-One platform operation strategy!
Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
实现领域驱动设计 - 使用ABP框架 - 领域逻辑 & 应用逻辑
My network relationship with "apifox"
leetcode 139. Word break word split (medium)
Most common usage of vim editor