首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
小红的最小三角形周长
[编程题]小红的最小三角形周长
热度指数:1307
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
小红拿到了一个数组,她希望取其中的三个数,使得以这三个数为边长的三角形周长尽可能小。你能帮帮她吗?
数据范围
,
注意:输入数据中
保证至少能形成一个三角形
示例1
输入
[2,8,4,11,9]
输出
19
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(17)
分享
纠错
提交结果有问题?
4个回答
5篇题解
开通博客
凉风起天末
发表于 2023-02-02 00:48:28
从数组中寻找周长最小的三角形,常规的思路是先排序,再从小到大依次搜索,再添加一些小优化就OK了。假设最短三角形的三条边依次是a、b、c(a<b<c),通过分析我们可以知道,b、c在排序后的数组中一定是相邻的,因为如果b、c中间还有数据(设为x),那么a、b、x会形成一个更短的三角形,与假
展开全文
牛客494732号
发表于 2023-05-23 10:39:54
package main import ( "sort" ) //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func
展开全文
knuke
发表于 2022-11-12 10:15:40
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution:
展开全文
o同学
发表于 2023-09-09 23:01:50
class Solution: def hongstriangle(self , nums: List[int]) -> int: # write code here n = len(nums) nums=sorted(nums)
展开全文
17c89
发表于 2024-09-10 18:25:14
import java.util.*; /** * NC414 小红的最小三角形周长 * @author d3y1 */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 *
展开全文
问题信息
贪心
二分
基础数学
排序
难度:
4条回答
17收藏
5171浏览
热门推荐
通过挑战的用户
查看代码
Jinjie0616
2022-09-14 17:00:36
牛客25212...
2022-09-12 01:53:53
牛客75959...
2022-09-12 01:31:27
半个西瓜半个夏
2022-09-09 11:57:19
西方不胜
2022-09-03 17:52:42
相关试题
下面使用贪心算法的是?
阿里巴巴
贪心
评论
(1)
牛牛的超市
动态规划
基础数学
评论
(5)
远亲不如近邻
排序
二分
评论
(13)
在大语言模型中,什么是"Gated...
大模型开发
评论
(1)
关于大模型“上下文窗口”的理解,以...
大模型概念
评论
(1)
小红的最小三角形周长
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型ArrayList * @return int整型 */ public int hongstriangle (ArrayList
nums) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型 */ int hongstriangle(vector
& nums) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def hongstriangle(self , nums ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int hongstriangle (List
nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ function hongstriangle( nums ) { // write code here } module.exports = { hongstriangle : hongstriangle };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def hongstriangle(self , nums: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func hongstriangle( nums []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @return int整型 */ int hongstriangle(int* nums, int numsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution def hongstriangle(nums) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ def hongstriangle(nums: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ fun hongstriangle(nums: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int hongstriangle (int[] nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ export function hongstriangle(nums: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func hongstriangle ( _ nums: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ pub fn hongstriangle(&self, nums: Vec
) -> i32 { // write code here } }
[2,8,4,11,9]
19