Majority Element&&Factorial Trailing Zeroes
来源:互联网 发布:丧尸世界知行天下 编辑:程序博客网 时间:2024/06/05 15:54
水题两道
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
You may assume that the array is non-empty and the majority element always exist in the array.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
class Solution {public: int majorityElement(vector<int> &num) { sort(num.begin(),num.end()); if(num[0]==num[num.size()/2]) return num[0]; else if(num[num.size()/2]==num[num.size()-1]) return num[num.size()-1]; else return num[num.size()/2]; }};
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
class Solution {public: int trailingZeroes(int n) { int count=0;int temp=n/5;while(temp!=0){count+=temp;temp=temp/5;}return count; }};
0 0
- Majority Element&&Factorial Trailing Zeroes
- Factorial Trailing Zeroes
- Factorial Trailing Zeroes
- Factorial Trailing Zeroes
- Factorial Trailing Zeroes
- [leetcode]Factorial Trailing Zeroes
- [LeetCode] Factorial Trailing Zeroes
- Leetcode Factorial Trailing Zeroes
- Leetcode: Factorial Trailing Zeroes
- 【Leetcode】Factorial Trailing Zeroes
- Factorial Trailing Zeroes
- leetcode:Factorial Trailing Zeroes
- Java-Factorial Trailing Zeroes
- Factorial Trailing Zeroes (Java)
- Factorial Trailing Zeroes
- Leetcode: Factorial Trailing Zeroes
- Leetcode: Factorial Trailing Zeroes
- Factorial Trailing Zeroes
- 黑马程序员——数组建立和操作
- 被潮水湮没的联想,能否借摩托罗拉发出怒吼?
- c++读书笔记
- VC 操作注册表
- 商业银行的表内业务与表外业务
- Majority Element&&Factorial Trailing Zeroes
- 下拉框
- 循环的使用之打印星号
- Windows下搭建PHP开发环境
- 2015-1-10 公司记录整理
- 负数小数不按四舍五入保留二位小数
- 马化腾力挺红米2,却忘记小米是头饿狼,迟早会噬扑微信
- java处理大文件方案
- 黑马入学试题