welcome to Qijie's Blog 薛其杰

如:

1,-1,2,-2,3,-3,4,5,6 - 最大递增子串长度为5.

最直观的O(N*N)算法:                     

 

        static int LongestSubString(int[] array)
        {
            int[] Lst = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if (array[i] > array[j] && Lst[i] < Lst[j] + 1)
                    {
                        Lst[i] = Lst[j] + 1;
                    }
                }
            }
            return Max(Lst);
        }

 

posted on 2013-01-14 11:05  零点零一  阅读(209)  评论(0编辑  收藏  举报