leetcode
文章平均质量分 67
卖鱼的小白菜
这个作者很懒,什么都没留下…
展开
-
Leetcode:Reverse Integer ,整数反转
#includeusing namespace std;class Solution {public: int reverse(int x) { bool isMinus = false; int tempX = x; if(x<0) { tempX = -tempX; isMinus = true; } int result原创 2014-11-09 22:44:09 · 485 阅读 · 0 评论 -
leetcode:Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.这个就是看第一位会不会被进位,如果被进位原创 2015-03-04 00:14:12 · 459 阅读 · 0 评论 -
leetcode:Permutations排列
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].根据给定的数组进行排列组合,这原创 2015-02-27 22:36:53 · 458 阅读 · 0 评论 -
leetcode:Rotate Array旋转数组
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as yo原创 2015-02-24 13:35:16 · 597 阅读 · 0 评论 -
leetcode:Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2015-02-25 14:10:14 · 458 阅读 · 0 评论 -
leetcode:sort colors排序颜色
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2014-11-24 20:24:30 · 700 阅读 · 0 评论 -
leetcode:Climbing Stairs
if (n<=0) return 0; if(n==1) return 1; if (n==2) return 2; int one = 1; int two = 2; int sum = 0; for (int i = 2; i < n; i++) { sum = one + two; one = two; two = su原创 2014-11-16 23:12:41 · 473 阅读 · 0 评论 -
leetcode:Candy糖果
dafsdf原创 2014-11-24 14:46:58 · 472 阅读 · 0 评论 -
leetcode:Remove Duplicates from Sorted Array去掉排序数组中重复的元素
class Solution {public: int removeDuplicates(int A[], int n) { if (A==NULL || n<1) return 0; int p_one = 0; for (int i = 1; i < n; ++i) if (A[i-1]!=A[i]) A[++p_one] = A[原创 2014-11-24 16:35:57 · 521 阅读 · 0 评论 -
leetcode:Pow(x, n)
Implement pow(x, n).没有考虑INT_MIN 和 INT_MAX导致错了两次贴上挫挫的代码class Solution {public: double pow(double x, int n) { if (x-0.000001 && n<0) return x;//it should be false; else if (x-0.000001)原创 2014-11-27 12:20:04 · 535 阅读 · 0 评论 -
leetcode:Remove Element删除元素
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2014-11-18 13:51:31 · 467 阅读 · 0 评论 -
leetcode:Single Number单个数字
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2014-11-18 13:20:34 · 456 阅读 · 0 评论 -
leetcode:Length of Last Word最后一个单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-11-17 13:06:08 · 469 阅读 · 0 评论 -
leetcode:Valid Palindrome 合法回文
class Solution {public: bool isPalindrome(string s) { int tail = s.length() -1 ; int head = 0; while (head < tail) { while (!isAlpha(s[tail]) && tail>head) --tail;原创 2014-11-17 12:53:52 · 584 阅读 · 0 评论 -
leetcode:ZigZag Conversion锯行转换
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2014-11-17 12:20:07 · 459 阅读 · 0 评论 -
leetcode:Palindrome Number 回文整数
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-11-15 19:16:49 · 493 阅读 · 0 评论 -
leetcode:Merge Sorted Array
#includeusing namespace std;class Solution {public: void merge(int A[], int m, int B[], int n) { if(m<1 && n<1) return; int length = m+n; while (m>0 && n>0) { if(A[m-1原创 2014-11-14 14:52:27 · 415 阅读 · 0 评论 -
leetcode:String to Integer (atoi) 字符串转化成整数
#include#include//#include//C自带的atoi函数对于空以及错误处理都是返回0,//对于正整数,忽略‘+’//尽量做到和自带的库函数一样,不过数字溢出部分,无法一样int atoi(const char * pstr){ if(pstr==NULL || *pstr=='0') return 0; int sum=0; int i;原创 2014-06-22 20:46:35 · 517 阅读 · 0 评论 -
Leetcode:Longest Common Prefix 最长公共前缀
Write a function to find the longest common prefix string amongst an array of strings.这题应该没什么难度,顶多就考虑一下如果strings头是空格算不算公用前缀,这个我也不知道,系统判定后才知道应该是算的。class Solution {public: string longestC原创 2015-03-04 20:24:21 · 470 阅读 · 0 评论