LeetCode-724. Find Pivot Index
来源:互联网 发布:任务清单统计系统 php 编辑:程序博客网 时间:2024/06/06 18:01
Description:
Example 1:
Example 2:
Note:
Solution (C++):
算法分析:
这道题比较简单,主要是要弄懂题目意思(还好有谷歌翻译),弄懂题目意思了自然就好做了。不罗嗦了。要注意的就是还要要考虑完全点。比如说i=0的时候。
程序分析:
要注意我最开始写的是
cur==(sum-nums[i])/2
这个判别条件不太好,因为除法如果是有小数,那也会取整。所以后来改成
cur*2==sum-nums[i]
编译通过。此外,在这里能看到cur*2。其实最好用位运算来替代。
cur<<1 ==sum-nums[i]
这样运算速度会更快,代码看起来也更巧妙。关于各种运算符的介绍可以参考这篇博客:c++位运算符
阅读全文
0 0
- LeetCode 724. Find Pivot Index
- LEETCODE: 724. Find Pivot Index
- LeetCode-724. Find Pivot Index
- 724. Find Pivot Index
- 724. Find Pivot Index
- LeetCode.724 Find Pivot Index
- leetcode 724 Find Pivot Index
- Find Pivot Index[Leetcode 724]
- Find Pivot Index(LeetCode 724)
- LWC 58:724. Find Pivot Index
- LeetCode724. Find Pivot Index
- [LeetCode]Find Pivot
- Find Pivot Index问题及解法
- leetcode index
- PIVOT
- pivot
- PIVOT
- pivot
- 二维码与条形码的生成和识别使用
- hibernate常见面试题详解
- php 验证身份证号码
- Python入门(一)——环境的搭建,创建第一个Python项目:Hello World
- stm32时钟问题简单介绍
- LeetCode-724. Find Pivot Index
- SuperMap iMobile for Android常见问题解答集锦(十四)
- Git基础命令
- Idea 下创建 maven管理的spring mvc项目,并上传到github
- 开通一个博客,开启一个更高的要求
- Ubuntu16.04虚拟机+ROS+树莓派控制小车
- Material Dialogs的使用
- sublime_Text3中snippet设置信息头(包括作者、日期)
- wps文档插入一个表格,怎么取消自动生成的编号