Linq int Max and min

using System;
using System.Linq;

class Difference {
    private int[] elements;
    public int maximumDifference;

    public Difference(int[] a){
        this.elements = a;
    }

    // Add your code here
    public void computeDifference(){

        var min = elements.Min( x=>x);
        var max = elements.Max( x=>x);
        var diff = max - min;


        this.maximumDifference = diff;
    }

// End of Difference Class

class Solution {
    static void Main(string[] args) {
        Convert.ToInt32(Console.ReadLine());
        
        int[] a = Console.ReadLine().Split(' ').Select(x=>Convert.ToInt32(x)).ToArray();
        
        Difference d = new Difference(a);
        
        d.computeDifference();
        
        Console.Write(d.maximumDifference);
    }
}


Compiler Message
Success
Input (stdin)
Download
  • 5
  • 9 3 5 1 2
Expected Output
Download
  • 8


Success
Input (stdin)
Download
  • 3
  • 1 2 5
Expected Output
Download
  • 4

留言

這個網誌中的熱門文章

香港袐密行動

要老是忘記, 我更記不起