---
title: "轩辕互动面试题目-----最大递增子序列（转）"
author: "jythoner"
date: "2010-01-05T09:30:42Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-01-05T09:30:42Z"
id: 562603
url: "https://jythoner.iteye.com/blog/562603"
---

数组A中存放很多数据，比如A={1,2,3,4,3,2,1,4,8,9,10};其中1,2,3,4/1,4,8,9,10都是递增子序列，1,4,8,9,10是最长的递增子序列。

寻找数组中的最长子序列，返回起始的索引值，如果没有递增子序列，那么返回-1.

实际就是连续判断A*是否比A大，下面是我的代码：


```java

int maxasds(int A[], int n)   
{   
    int     lastCount;   
    int     count;   
    int     max, idx;   
    int     i;   
  
    max = 1;   
    idx = -1;   
    lastCount = 0;   
    count = 1;   
    for(i = 1; i < n; i++) {   
        if(A[i] > A[i - 1]) {   
            lastCount = 0;   
            count++;   
        } else {   
            lastCount = count;   
            count = 1;   
        }   
  
        if(max < lastCount) {   
            max = lastCount;   
            idx = i - lastCount;   
        }   
    }   
  
    return idx;   
}  

```