面试100题-95

95.华为面试题
1 判断一字符串是不是对称的,如:abccba

package cn.emma.interview_95;

import java.util.Scanner;

public class Reverse {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String input = (String) scanner.next();
			
			Stack stack = new Stack();
			int i =0;
			for(; i  {
	private int top;
	private List values;
	
	public Stack(){
		top = -1;
		values = new ArrayList();
	}
	public void push(T value){
		values.add(++top, value);
	}
	public T pop(){
		if(top !=-1){
			return values.get(top--);
		}
		return null;
	}
	
}

2.用递归的方法判断整数组a[N]是不是升序排列
package cn.emma.interview_95;

public class Asc {
	public static boolean ascArray(int[] a, int n){
		if(n == 1){
			return true;
		}
		else if(ascArray(a,n-1)){
			return (a[a.length - n] <= a[a.length - n +1]);
		}
		return false;
	}
	public static void main(String[] args) {
		int[] a = {1,2,3,4,6,7,10,9};
		System.out.println(ascArray(a, a.length));
	}
}

你可能感兴趣的:(面试)