当前位置:网站首页>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;
}
};边栏推荐
- C # read and write customized config file
- 【mysql学习笔记27】存储过程
- How to create an exclusive vs Code theme
- LeetCode+ 71 - 75
- 漏刻有时API接口实战开发系列(14):身份证实名鉴权验证
- ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
- 【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案
- Vscode automatically formats code according to eslint specification
- 【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
- Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list
猜你喜欢

Redisson uses the complete solution - redisson official documents + Notes (Part 1)

C # read and write customized config file

如何使用layui将数据库中的数据以表格的形式展现出来

组件的自定义事件②
![[programming training] delete public characters (hash mapping) + team competition (greedy)](/img/cd/63eb9da1e8956df0763797f079b67f.png)
[programming training] delete public characters (hash mapping) + team competition (greedy)

Gru of RNN

H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?

熱烈祝賀五行和合酒成功掛牌

038 network security JS

【编程强训】删除公共字符(哈希映射)+组队竞赛(贪心)
随机推荐
redisson使用全解——redisson官方文档+注释(中篇)
[target detection] yolov5, the shoulder of target detection (detailed principle + Training Guide)
熱烈祝賀五行和合酒成功掛牌
浅谈CVPR2022的几个研究热点
Conscience Amway universal wheel SolidWorks model material website
力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
How do the top ten securities firms open accounts? In addition, is it safe to open a mobile account?
如何让两融交易更极速
matlab保存DB4i深度相机图片
redisson看门狗机制,redisson看门狗性能问题,redisson源码解析
【微服务|openfeign】Feign的日志记录
奥迪AUDI EDI 项目中供应商需要了解哪些信息?
She is the "HR of others" | ones character
2022年茶艺师(中级)复训题库及答案
The computer has a network, but all browser pages can't be opened. What's the matter?
力扣每日一题-第32天-1822.数组元素积的符号
[Shenzhen IO] precise Food Scale (some understanding of assembly language)
go通用动态重试机制解决方案的实现与封装
Long way to go with technology
【无标题】