博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Second Max of Array
阅读量:4612 次
发布时间:2019-06-09

本文共 694 字,大约阅读时间需要 2 分钟。

Find the second max number in a given array.

Example

Given [1, 3, 2, 4], return 3.

Given [1, 2], return 1.

Notice : Attention corner case. Communicate with Interviewer.

public class Solution {    /**     * @param nums: An integer array.     * @return: The second max number in the array.     */    public int secondMax(int[] nums) {       int max = Math.max(nums[0],nums[1]);       int secondMax = Math.min(nums[0],nums[1]);       for (int i = 2; i < nums.length; i++) {               if (max <= nums[i]) {                   secondMax = max;                   max = Math.max(nums[i],max);               }       }       return secondMax;    }}

 

转载于:https://www.cnblogs.com/FLAGyuri/p/7216830.html

你可能感兴趣的文章
如何删除xcode项目中不再使用的图片资源
查看>>
编写用例文档
查看>>
解决WPF两个图片控件显示相同图片因线程占用,其中一个显示不全的问题
查看>>
寻觅Azure上的Athena和BigQuery (二):神奇的PolyBase
查看>>
编程题练习
查看>>
mac os安装vim74
查看>>
Linux内存管理原理
查看>>
Java 8 Lambda 表达式
查看>>
BZOJ-3289 Mato的文件管理
查看>>
自旋锁和互斥锁的区别
查看>>
react混合开发APP,资源分享
查看>>
入门篇
查看>>
【洛谷1829】 [国家集训队] Crash的数字表格(重拾莫比乌斯反演)
查看>>
[转]免费api大全
查看>>
git 认证问题之一的解决 : http ssh 互换
查看>>
sql where 1=1作用
查看>>
搜索算法----二分查找
查看>>
Python语言编程
查看>>
事务并发、事务隔离级别 .
查看>>
[poj 1469]Courses
查看>>