![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 70
xiaowovicky
这个作者很懒,什么都没留下…
展开
-
258. Add Digits
class Solution {public: int addDigits(int num) { do{ int n=num,i; for(i=0;n!=0;i++) n/=10; int a[i]; int m=num;原创 2016-05-16 15:29:23 · 133 阅读 · 0 评论 -
347. Top K Frequent Elements
class Solution {public: vector topKFrequent(vector& nums, int k) { map mp; map ::iterator i; for (int i=0;i mp[nums[i]]++; //Map中的元素是自动按key升序排序,所以不能对map用so原创 2016-06-14 11:09:52 · 147 阅读 · 0 评论 -
217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2016-05-17 10:53:17 · 193 阅读 · 0 评论 -
263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc原创 2016-05-19 15:22:34 · 152 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
class Solution {public: int maxProfit(vector& prices) { if(prices.size() int min=prices[0],maxpro=0,max=0; for (int i=1;i if(prices[i-1]>prices[i]){原创 2016-05-19 17:48:44 · 122 阅读 · 0 评论 -
21. Merge Two Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2016-05-20 11:47:18 · 143 阅读 · 0 评论 -
118. Pascal's Triangle(使用二维vector)
class Solution {public: vector> generate(int numRows) { vector p; vector> pp; if(numRows else{ if(numRows==1){ p.push_back(1);原创 2016-05-21 14:13:20 · 190 阅读 · 0 评论 -
119. Pascal's Triangle II
class Solution {public: vector getRow(int rowIndex) {/* vector p; if(rowIndex else{ if (rowIndex==0){ p.push_back(1); }原创 2016-05-23 10:36:32 · 125 阅读 · 0 评论 -
169. Majority Element
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原创 2016-05-17 09:19:01 · 112 阅读 · 0 评论 -
344. Reverse String (Iterator简介)
Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.class Solution {public: string reverseString(string s) {原创 2016-05-16 10:03:06 · 246 阅读 · 0 评论 -
238. Product of Array Except Self
class Solution {public: vector productExceptSelf(vector& nums) { int n=nums.size(),right=1,left=1; vector res(n,1); for(int i=0;i res[i]*=right; rig原创 2016-06-14 11:34:02 · 167 阅读 · 0 评论