Data Structure Array: Find the minimum distance between two numbers
2024-08-29 20:36:54
http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; int mindis(int arr[], int n, int x, int y) {
int pre = ;
while (arr[pre] != x && arr[pre] != y) pre++;
int i = pre + ;
int ans = n;
for (; i < n; i++) {
if (arr[i] != x && arr[i] != y) continue;
if (arr[i] != arr[pre]) ans = min(ans, i - pre);
pre = i;
}
return ans;
} int main() {
int arr[] = {, , , , , , , , , , , };
cout << mindis(arr, , , ) << endl;
return ;
}
最新文章
- python3-day1-python简介及入门
- js如何判断一个数组
- 03-VTK基础概念(2)
- 机器翻译(noip2010)
- Java基础知识强化之IO流笔记63:随机访问流RandomAccessFile
- Android Sutido 编译速度优化
- Asp.net实现在线人数统计功能代码实例
- (2010-8-31) awk内存泄漏以及缓慢的正则表达式计算速度
- WordPress插件制作笔记(二)---Second Plugins Demo
- mysql进阶(八)怎么对varchar类型排序问题
- 500G !!史上最全的JAVA全套教学视频网盘分享 (JEECG开源社区)
- Docker面试题
- 通过iostat来查看linux硬盘IO性能|实例分析
- Win10系列:C#应用控件基础11
- Hadoop 4 MapReduce
- Python3基础 try-except else进行配合
- 2018.07.06 POJ 1459 Power Network(多源多汇最大流)
- 第7章 	使用寄存器点亮LED灯—零死角玩转STM32-F429系列
- Mondrian系列
- Linux命令-目录处理命令:cd
热门文章
- [linux]netstat命令详解-显示linux中各种网络相关信息
- Spark on Intellij IDEA
- javax.mail Java Extension(扩展)
- Paxos 学习总结
- css 温故而知新 select-option 文字方向居右
- [LeetCode]Palindrome Number 推断二进制和十进制是否为回文
- Java和C++ 比較
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: Unknown column &#39;viewpoint&#39; in &#39;field list&#39;
- linux 上拷贝文件到windows 上 文件出现锁的文件
- 多媒体开发之--- h264 图像、帧、片、NALU