_250.FoxAndSightseeing.getMin C# (CSharp) Method

getMin() public method

public getMin ( int position ) : int
position int
return int
        public int getMin(int[] position)
        {
            int res = 1000000000;
            int[] t = new int[position.Length - 1];
            for (int i = 1; i < position.Length - 1; i++)
            {
                int x = 0;
                for (int b = 0; b < position.Length; b++)
                {
                    if (b != i)
                    {
                        t[x] = position[b];
                        x++;
                    }
                }
                int temp = 0;
                for (int a = 0; a < t.Length - 1; a++)
                    temp += Math.Abs(t[a] - t[a + 1]);
                res = Math.Min(res, temp);
            }
            return res;
        }

Usage Example

コード例 #1
0
ファイル: Program.cs プロジェクト: Oscarbralo/TopBlogCoder
 static void Main(string[] args)
 {
     FoxAndSightseeing x = new FoxAndSightseeing();
     int[] a = { 1, 4, -1, 3 };
     Console.WriteLine(x.getMin(a));
     Console.ReadLine();
 }
All Usage Examples Of _250.FoxAndSightseeing::getMin
FoxAndSightseeing