Created
November 21, 2016 00:51
-
-
Save jianminchen/7401c0b6108659df7d03abd2576cb1cf to your computer and use it in GitHub Desktop.
Minimum Cost - study code - failed to score 35, only 15, run-time error - try to figure out things in the code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
class Solution { | |
static void Main(String[] args) { | |
var line = Console.ReadLine().Split(' '); | |
var prices = Console.ReadLine().Split(' '); | |
List<int> loss = new List<int>(); | |
for (var i = 0; i < prices.Length - 1; i++) | |
{ | |
for (var j = i + 1; j < prices.Length; j++) | |
{ | |
var priceI = Int32.Parse(prices[i]); | |
var priceJ = Int32.Parse(prices[j]); | |
if (priceI < priceJ) continue; | |
loss.Add(priceI - priceJ); | |
} | |
} | |
var minLoss = loss.Min(); | |
Console.WriteLine(minLoss); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment