csharp基础练习题:查找列表的最大值和最小值【难度:0级】:
你的任务是做两个函数,
最大
和
最小值(在PHP和Python中为`maximum`和`minimum`),它们采用整数的向量数组/向量
将
列为输入和输出,分别是该数组/向量中的最大和最小数字.
# 例子
```cpp
max({4,6,2,1,9,63,-134,566})返回566
min({ - 52,56,30,29,-54,0,-110})返回-110
max({5})返回5
min({42,54,65,87,0})返回0
max({4,6,2,1,9,63,-134,566})返回566
min({ - 52,56,30,29,-54,0,-110})返回-110
max({5})返回5
min({42,54,65,87,0})返回0
max([4,6,2,1,9,63,-134,566])返回566
min([ - 52,56,30,29,-54,0,-110])返回-110
max([5])返回5
min([42,54,65,87,0])返回0
maximun([4,6,2,1,9,63,-134,566])返回566
minimun([ - 52,56,30,29,-54,0,-110])返回-110
maximun([5])返回5
minimun([42,54,65,87,0])返回0
max([4,6,2,1,9,63,-134,566])返回566
min([ - 52,56,30,29,-54,0,-110])返回-110
max([5])返回5
min([42,54,65,87,0])返回0
max([4,6,2,1,9,63,-134,566])返回566
min([ - 52,56,30,29,-54,0,-110])返回-110
max([5])返回5
min([42,54,65,87,0])返回0
max({4,6,2,1,9,63,-134,566})返回566
min({ - 52,56,30,29,-54,0,-110})返回-110
max({5})返回5
min({42,54,65,87,0})返回0
笔记
- 您可能会认为没有任何空数组/向量.
编程目标:
public class Kata
{
public int Min(int[] list)
{
}
public int Max(int[] list)
{
}
}
测试样例:
namespace Solution {
using NUnit.Framework;
using System;
// TODO: TDD development by writing your own tests
[TestFixture]
public class SolutionTest
{
public void TestExamples()
{
Assert.AreEqual(-110, new Kata().Min(new []{-52, 56, 30, 29, -54, 0, -110}));
Assert.AreEqual(0, new Kata().Min(new []{42, 54, 65, 87, 0}));
Assert.AreEqual(566, new Kata().Max(new []{4,6,2,1,9,63,-134,566}));
Assert.AreEqual(5, new Kata().Max(new []{5}));
}
}
最佳答案(多种解法):
更多关联题目:
csharp基础练习题:奇数之和【难度:1级】–景越C# 经典编程题库,不同难度C# 练习题,适合自学C# 的新手进阶训练
csharp基础练习题:Alan Partridge III - 伦敦【难度:1级】–景越C# 经典编程题库,不同难度C# 练习题,适合自学C# 的新手进阶训练
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/find-maximum-and-minimum-values-of-a-list