/**给你一个整数数组 nums 和一个整数 k ,判断数组中是否存在两个 不同的索引 i 和 j * ,满足 nums[i] == nums[j] 且 abs(i - j) <= k (绝对值)。如果存在,返回 true ;否则,返回 false 。*/
- public class Demo25 {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- System.out.println("请输入一个整数k");
- int k=sc.nextInt();
- System.out.println("请输入数组元素个数");
- int n=sc.nextInt();
- System.out.println("请依次输入数组元素");
- int[] nums=new int[n];
- for (int i = 0; i
- nums[i]=sc.nextInt();
- }
- for (int i = 0; i
1 ; i++) { - for (int j = i+1; j <=i+k&&j
- if(nums[i]==nums[j]){
- System.out.println(true);
- return;
- }
- }
- }
- System.out.println(false);
- }
- }
-
相关阅读:
正则表达式语法与应用案例
细数SkyEye异构仿真的5大特色
【Spring Cloud】Ribbon 实现负载均衡的原理,策略以及饥饿加载
Linux常用命令——find命令大全
一文带你深入闭包与作用域链原理(无惧面试)
k8s 中的 Pod 细节了解
什么是校园水电表预付费系统?
【iOS】—— weak的基本原理
智慧工地扬尘监测系统
C++项目 - 负载均衡OJ - 1 - 项目概述
-
原文地址:https://blog.csdn.net/m0_72084166/article/details/133777162