# 845. Longest Mountain in Array

[Link](https://leetcode.com/problems/longest-mountain-in-array/)

**Solution**

這題就是考慮各種前後數大小的case(上升up, 下行down, 持平)，沒什麼技巧。

唯一的難處就是要考慮到edge case。( 正在down時遇到up的情形)

```java
    public int longestMountain(int[] A) {
        int down = 0, up = 0, max = 0;
        for(int i = 1; i < A.length; i++){
            if(A[i-1] == A[i]) up = down = 0;
            else if(A[i] < A[i-1] && up > 0) down++;
            else if(A[i] > A[i-1]){
                if(down == 0){
                    up++; 
                }
                else{
                    down = 0;
                    up = 1;
                }
            }
            if(up > 0 && down > 0 && up + down + 1 > max) max = up+down+1;
        }
        return max;
    }
```
