public class Solution {
    public int[] NextGreaterElement(int[] findNums, int[] nums) {
        var list = new List<int>();

            foreach (var num in findNums)
            {
                for (int i = 0; i < nums.Length; i++)
                {
                    if (num == nums[i])
                    {
                        var cur = -1;
                        for (int j = i + 1; j < nums.Length; j++)
                        {
                            if (nums[j] > num)
                            {
                                cur = nums[j];
                                break;
                            }
                        }
                        list.Add(cur);
                    }
                }
            }

            //foreach (var l in list)
            //{
            //    Console.WriteLine(l.ToString());
            //}

            return list.ToArray();
    }
}

https://leetcode.com/problems/next-greater-element-i/#/description

posted on 2017-04-19 10:53  Sempron2800+  阅读(180)  评论(0编辑  收藏  举报