刷题
qq_28388867
这个作者很懒,什么都没留下…
展开
-
leetcode 202. Happy Number
Happy NumberWrite an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of...原创 2018-12-21 17:48:48 · 112 阅读 · 0 评论 -
leetcode 198. House Robber
House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that ...原创 2018-12-21 17:49:57 · 93 阅读 · 0 评论 -
leetcode 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5 Accepted增加头节点,以防止溢出class S...原创 2018-12-21 18:19:54 · 93 阅读 · 0 评论 -
leetcode 204. Count Primes 计算质数的数目
Count the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.常规方法很容易超时,要使用高效的算法,这是googl...原创 2018-12-21 19:23:37 · 122 阅读 · 0 评论 -
leetcode 206. Reverse Linked List
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLclass Solution {public: ListNode* reverseList(ListNode* head) { ...原创 2018-12-21 20:12:05 · 98 阅读 · 0 评论 -
Boyer-Moore Voting Algorithm 多数投票算法
Boyer-Moore Voting Algorithm 多数投票算法##Majority Element题目介绍:给定一个长度为n的数组的时候,找出其中的主元素,即该元素在数组中出现的次数大于n/2的取整。题目中已经假定所给的数组一定含有元素,且主元素一定存在。在刷leetcode 169. Majority Element 的时候发觉这个算法相当巧妙,hash表的找主成分方法时间复杂度是O...原创 2018-12-18 17:29:13 · 337 阅读 · 0 评论 -
leetcode 172. Factorial Trailing Zeroes乘方后面带几个零
Factorial Trailing Zeroes问n的乘方后面带几个零,这是数学题,重点在于因数中有几个10,也就是有几个2和5,而5比2要稀缺得多所以找到因数中一共是几个5就可以了。我的代码class Solution {public: int trailingZeroes(int n) { int ret=0; while(n=n/5)...原创 2018-12-18 17:50:17 · 85 阅读 · 0 评论 -
leetcode 189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.感觉难度不大,但是注释的两句改了好久才改好,还是水平太低class Solution {public: void rotate(vector<int>& nums, int k) { i...原创 2018-12-18 19:28:24 · 97 阅读 · 1 评论