当前位置:网站首页>Li Kou daily question - Day 32 -1822 Symbol of array element product
Li Kou daily question - Day 32 -1822 Symbol of array element product
2022-07-01 07:48:00 【Chongyou research Sen】
2022.6.30 Did you brush the questions today ?
subject :
Known functions signFunc(x) Will be based on x The positive and negative of returns a specific value :
If x Positive number , return 1 .
If x It's a negative number , return -1 .
If x Is equal to 0 , return 0 .
Give you an array of integers nums . Make product Is an array nums The product of the values of all elements in .
return signFunc(product) .
analysis :
Give you an array , Multiply all the elements of the array to get ans, And then determine ans The corresponding value is output in the positive and negative relationship of .
Ideas : You can't multiply the result directly here ( Because the title requires ), So let's change our mind , As long as the element is judged inside =0, Then go straight back 0, If there are negative numbers in the element , Record once , Finally, we only need to judge the number of negative numbers to output the results .
analysis :
1. Violent solution
class Solution {
public:
int arraySign(vector<int>& nums) {
bool sum = true;
for (auto num : nums)
{
if (num == 0)
{
return 0;
}
if (num < 0)
{
sum = !sum;
}
}
return sum ? 1 : -1;
}
};边栏推荐
- 2022茶艺师(初级)操作证考试题库及模拟考试
- The database is locked. Is there a solution
- The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone
- MATLAB之基础知识
- 【编程强训2】排序子序列+倒置字符串
- redisson使用全解——redisson官方文檔+注釋(上篇)
- 2022 test questions and mock examinations for main principals of hazardous chemicals business units
- 【mysql学习笔记28】存储函数
- 【无标题】
- ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
猜你喜欢
![[programming training] delete public characters (hash mapping) + team competition (greedy)](/img/cd/63eb9da1e8956df0763797f079b67f.png)
[programming training] delete public characters (hash mapping) + team competition (greedy)

Minecraft 1.16.5 module development (51) tile entity

iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事

STM32 uses esp01s to go to the cloud, mqtt FX debugging

【编程强训2】排序子序列+倒置字符串

2022 test question bank and simulation test of tea master (primary) operation certificate

redisson使用全解——redisson官方文档+注释(上篇)

Apple account password auto fill

IMDB practice of emotion classification (simplernn, LSTM, Gru)

下载Xshell和Xftp
随机推荐
IMDB practice of emotion classification (simplernn, LSTM, Gru)
C# Newtonsoft. Use of job in JSON
matlab保存DB4i深度相机图片
【R语言】年龄性别频数匹配 挑选样本 病例对照研究,对年龄性别进行频数匹配
redisson使用全解——redisson官方文档+注释(上篇)
组件的自定义事件②
华为ModelArts训练Alexnet模型
Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
[软件] phantomjs屏幕截图
【推荐系统】美团外卖推荐场景的深度位置交互网络DPIN的突破与畅想
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
atguigu----脚手架--02-使用脚手架(2)
[software] phantomjs screenshot
2022 tea master (intermediate) recurrent training question bank and answers
TCP/UDP 通信问题整理
Basic number theory -- combinatorial number
【微服务|openfeign】Feign的日志记录
The computer has a network, but all browser pages can't be opened. What's the matter?
The triode is a great invention
2022 test questions and mock examinations for main principals of hazardous chemicals business units