[LeetCode]至少是其他数字两倍的最大数
题目

代码
class Solution {
public:
int dominantIndex(vector<int>& nums) {
vector<int> sortedNums=nums;
std::sort(sortedNums.begin(),sortedNums.end());
int last=sortedNums[nums.size()-1];
int pre=sortedNums[nums.size()-2];
int index=0;
for(index=0;index<nums.size();index++)
{
if(last==nums[index])
break;
}
if(last!=0&&pre==0)
return index;
if(last/pre>2||(last/pre==2&&last%pre>=0))
return index;
return -1;
}
};
[LeetCode]至少是其他数字两倍的最大数的更多相关文章
- LeetCode:至少是其他数字两倍的最大数【747】
LeetCode:至少是其他数字两倍的最大数[747] 题目描述 在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素 ...
- Java实现 LeetCode 747 至少是其他数字两倍的最大数(暴力)
747. 至少是其他数字两倍的最大数 在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 ...
- Leetcode747至少是其他数字两倍的最大数
Leetcode747至少是其他数字两倍的最大数 在一个给定的数组nums中,总是存在一个最大元素 .查找数组中的最大元素是否至少是数组中每个其他数字的两倍.如果是,则返回最大元素的索引,否则返回-1 ...
- LeetCode747 至少是其他数字两倍的最大数
在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums = [3, ...
- [LeetCode] Largest Number At Least Twice of Others 至少是其他数字两倍的最大数
In a given integer array nums, there is always exactly one largest element. Find whether the largest ...
- [Swift]LeetCode747. 至少是其他数字两倍的最大数 | Largest Number At Least Twice of Others
In a given integer array nums, there is always exactly one largest element. Find whether the largest ...
- [LC]747题 Largest Number At Least Twice of Others (至少是其他数字两倍的最大数)
①中文题目 在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums ...
- Leetcode747.Largest Number At Least Twice of Others至少是其他数字两倍的最大数
在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums = [3, ...
- C#LeetCode刷题之#747-至少是其他数字两倍的最大数( Largest Number At Least Twice of Others)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3746 访问. 在一个给定的数组nums中,总是存在一个最大元素 ...
- 747. Largest Number At Least Twice of Others比所有数字都大两倍的最大数
[抄题]: In a given integer array nums, there is always exactly one largest element. Find whether the l ...
随机推荐
- NOI2011阿狸的打字机
题目链接 昨天晚上yy出了一个做法后,感觉...好难打啊...,于是先回去休息.今天来打时,还是感觉细节好多,于是就打了两个小时.打完过了编译后,居然过了样例,直接交,尼玛居然过了???......还 ...
- 经典排序算法之-----选择排序(Java实现)
其他的经典排序算法链接地址:https://blog.csdn.net/weixin_43304253/article/details/121209905 选择排序思想: 思路: 1.从整个数据中挑选 ...
- 34.HyperLinkedModelSerializer详解
HyperLinkedModelSerializer继承ModelSerializer,只是自动多出了一个url字段,其他都是一样的 不同之处在于使用超链接来表示关联关系而不是主键 默认情况下Hype ...
- day02-HTML02
4.HTML 4.3HTML基本标签 4.3.9表格(table)标签 基本语法: <table border="边框宽度" cellspacing="空隙大小&q ...
- 【原创】All in One i.MXRT1050/RT1020 SPI Flash Algorithm for J-Flash
2020年,这个给大家一种很漫长的恍惚感的一年,终于是过去了.这一年我们很多新的人生第一次就这么被发生了,第一次居家办公这么长时间(很多人肥膘都长了不少,我却瘦了2斤,不知是工作太积极了还是被家里小怪 ...
- 【单元测试】Junit 4(四)--Junit4参数化
1.0 前言 JUnit 4引入了一项名为参数化测试的新功能.参数化测试允许开发人员使用不同的值反复运行相同的测试. 1.1 参数化设置 这里我们直接上例子吧. 题目: 输入小写的字符串.如字 ...
- 第2-1-2章 传统方式安装FastDFS-附FastDFS常用命令
目录 3 安装配置 3.1 安装GCC 3.2 安装libevent 3.3 安装libfastcommon 3.4 安装FastDFS 3.5 安装fastdfs-nginx-module 3.5 ...
- hwlog----types.go
// Copyright(C) 2021. Huawei Technologies Co.,Ltd. All rights reserved.// Package hwlog provides the ...
- 图文详解在VMware Workstation 16 PRO虚拟机上安装Ubuntu 22.04.5 linux系统
一.下载Ubuntu linux系统镜像 机构 下载地址 官网地址 https://cn.ubuntu.com/download 南京大学 https://mirrors.nju.edu.cn/ubu ...
- Linux 交叉编译使用代码覆盖GCOV及LCOV
1. GCOV GCOV是GCC自带的代码覆盖工具,GCOV. 在 GCC 编译的时加入特殊的编译选项,生成可执行文件,和 *.gcno: 运行(测试)生成的可执行文件,生成了 *.gcda 数据文件 ...