Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created November 21, 2016 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/7401c0b6108659df7d03abd2576cb1cf to your computer and use it in GitHub Desktop.
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
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