Love丶FFC's Blog

LintCode_easy:有效的三角形

2019-09-02 09:05:47
阅读:552   •   评论:8
标签:,

描述

给出三个整数 abc, 如果它们可以构成三角形,返回 true.

三角形的定义 (Wikipedia)

样例

样例 1:

输入 : a = 2, b = 3, c = 4
输出 : true

样例 2:

输入 : a = 1, b = 2, c = 3
输出 : false

编程语言:Java

解题思想:

1.使用三角形定义。

2.使用条件表达式+if判断。

时间复杂度:O(1)

IDE代码如下:

  1. package LintCode_Easy;
  2.  
  3. public class _765{
  4.  
  5. public static void main(String[] args) {
  6. int a = 2, b = 3, c = 4;
  7. boolean judge;
  8. if (Math.max(Math.max(a, b), c) == a)
  9. {
  10. judge = (b+c>a)?true:false;
  11. }
  12. else if (Math.max(Math.max(a, b), c) == b)
  13. {
  14. judge = (a+c>b)?true:false;
  15. }
  16. else
  17. {
  18. judge = (a+b>c)?true:false;
  19. }
  20. System.out.println(judge);
  21. }
  22.  
  23. }
  24.  

LintCode编辑器代码如下:

  1. public class Solution {
  2. public boolean isValidTriangle(int a, int b, int c) {
  3. boolean judge;
  4. if (Math.max(Math.max(a, b), c) == a)
  5. {
  6. judge = (b+c>a)?true:false;
  7. }
  8. else if (Math.max(Math.max(a, b), c) == b)
  9. {
  10. judge = (a+c>b)?true:false;
  11. }
  12. else
  13. {
  14. judge = (a+b>c)?true:false;
  15. }
  16. return judge;
  17. }
  18. }

评论板

共有 8 条评论

  1. fruinly

    where to buy cialis cheap In the Victimization Scale, participants were asked to answer how often their mates victimized them while in the Bullying Scale they were asked to answer how often they did bullying behaviors

  2. FoorryNox

    These are listed below according to the WHO groupings; Africa, Americas, Eastern Mediterranean EM, South East Asia SEA and Western Pacific WP Table 1 priligy review members 1 Live birth rate per couple Show forest plot

  3. Preliaf

    Hagos GK et al 2007 Colon cancer chemoprevention by a novel NO chimera that shows anti inflammatory and antiproliferative activity in vitro and in vivo buying cialis online safe

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名: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 -

已运行:

访问量:503766