数组 - Array

2019-01-04  本文已影响0人  反射弧长一光年
int array = new int[size];
int array = new int[]{1,2,3,4};
public class Solution {
    /**
     * @param matrix: an input array
     * @return: res[0]: the maximum,res[1]: the 2nd maximum
     */
    public int[] first2Max(int[] matrix) {
        if (nums == null || nums.length == 0) {
            return new int[0];
        }
        int[] res = new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE};
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > res[1]) {
                if (nums[i] > res[0]) {
                    res[0] = nums[i];
                    res[1] = res[0];
                } else {
                    res[1] = nums[i];
                }
            }
        }
        return res;
    }
}

Lintcode 相关题目

上一篇 下一篇

猜你喜欢

热点阅读