当前位置:网站首页>Find the minimum value and location in multiple numbers (with repetition)
Find the minimum value and location in multiple numbers (with repetition)
2022-07-23 15:50:00 【Still work hard!】
Find the minimum value among the given numbers , And get the position of the minimum value in the number .
- When there are no duplicate values in multiple numbers , Just walk through the list that stores these numbers ;
- When there are duplicate values in multiple numbers , You can add a new list
MinIndexTo store the location of the current minimum , When the minimum value changes during traversal , It needs to be removedMinIndexAnd add the position of the new minimum value toMinIndexin , When there is a duplicate value of the minimum value in the traversal process , You need to fill in the position of this valueMinIndexin .
public static List<int> FindMin(List<float> NumList)
{
List<int> MinIndex = new List<int>() {
0 };
float MinNum = NumList[0];
for (int i = 1; i < NumList.Count; i++)
{
// If the minimum value changes , Then change the minimum value ,
// And clear the List, And add the position of the current value
if (MinNum > NumList[i])
{
MinNum = NumList[i];
MinIndex.Clear();
MinIndex.Add(i);
}
// If duplicate values occur , The position of the current value is also added to the position of the record minimum List
else if (MinNum == NumList[i])
{
MinIndex.Add(i);
}
}
// When the minimum value repeats , Record the position of the minimum value List There will be multiple numbers
// If only one minimum position is required , Yes, you can. List Sort at random , Then go to List[0] that will do
if (MinIndex.Count > 1)
{
System.Random rand = new System.Random();
List<int> RandList = new List<int>();
foreach (int i in MinIndex)
{
RandList.Insert(rand.Next(RandList.Count), i);
}
return RandList;
}
else
{
return MinIndex;
}
}
边栏推荐
- Deep understanding of CAS (spin lock)
- 自定义封装弹出框(带进度条)
- [pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.
- day14函数模块
- Custom encapsulation pop-up box (with progress bar)
- VMware virtual machine download, installation and use tutorial
- C# 关闭当前电脑指令
- (BFS) template + example (maze, eight digits)
- 链表合并(暑假每日一题 3)
- Xlswriter - Excel export
猜你喜欢

Axure advanced

奔驰新能源产品线:豪华新能源市场或将改变格局

Part II how to design an RBAC authority system

Safe operation 7.22

Time series data in industrial Internet of things

Idea starts multiple projects at once

Mathematical Modeling Typesetting

select......for update 语句的功能是什么? 会锁表还是锁行?

Remember SQL optimization once

Idea five free plug-ins to improve efficiency
随机推荐
Gear 月度更新|6 月
SCA在得物DevSecOps平台上应用
Safety 7.18 operation
AWS篇1
Self capacitance touch controller for wearable devices it7259q-13, it7259ex-24
一个悄然崛起的国产软件,太强了!
[200 opencv routines] 225. Fourier descriptor for feature extraction
Batch deletion with RPM -e --nodeps
C# 关闭当前电脑指令
后缀表达式(暑假每日一题 4)
Kirin V10 source code compilation qtcreater4.0.3 record
【无标题】
Where can I download airserver? How to use tutorial
Find the source code of the thesis
C语言经典例题-商品检验码
String and integer convert each other
Part I basic information of the project
C语言学习笔记
pydensecrf安装
md5强碰撞,二次解码,