I dont think this o(n) but it still passed.. LOL (JAVA solution)


#1
 public class Solution {
public int perfectPeak(ArrayList<Integer> A) {
    int n = A.size();
	
	for(int i = 1; i < n - 1; i++) {
		int temp = A.get(i);
		int k = i - 1;
		int j = i + 1;
		while(true) {
			if(k >= 0 && A.get(k) < temp) {
				k--;
			}
			if(j < n && A.get(j) > temp) {
				j++;
			}
			if( (k >= 0 && A.get(k) >= temp) || ( j < n && A.get(j) <= temp)) break;
			if( k < 0 && j >= n) {
			// 	System.out.println("The peak element is: " + temp);
				return 1;
			}
		}
	}
	
	return 0;
}

}