Love丶FFC's Blog

LintCode_naive:三数之中的最大值

2019-08-26 23:01:22
阅读:566   •   评论:3
标签:,

描述

给三个整数,求他们中的最大值。

样例

样例  1:
	输入:  num1 = 1, num2 = 9, num3 = 0
	输出: 9
	
	样例解释: 
	返回三个数中最大的数。

样例 2:
	输入:  num1 = 1, num2 = 2, num3 = 3
	输出: 3
	
	样例解释: 
	返回三个中最大的数字。

编程语言:Java

解题思想:

1.使用if判断或者嵌套调用Math.max方法

时间复杂度:O(1)

IDE代码如下:

  1. package Lintcode_Naive;
  2.  
  3. public class _283 {
  4.  
  5. public static void main(String[] args) {
  6. //因为比较简单 直接调用api
  7. int num1=5,num2=4,num3=6;
  8. System.out.println(Math.max(Math.max(num1, num2), num3)); //调用两次max方法
  9. }
  10.  
  11. }

LintCode编辑器代码如下:

  1. public class Solution {
  2. public int maxOfThreeNumbers(int num1, int num2, int num3) {
  3. return Math.max(Math.max(num1, num2), num3);
  4. }
  5. }

评论板

共有 3 条评论

  1. Jorcift

    Meaning, you can t only take one or two kinds and expect results best site to buy cialis online

  2. intuido

    For instance, Shi et al buy cialis pro We found that hepcidin Hamp transcript levels were significantly decreased in mice on the low iron diet and in Fpn О”IE mice Figure 2E

  3. intuido

    Monitor Closely 1 milnacipran, asenapine propecia vs generic Isaias xzdkavuKSL 6 29 2022

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:502270