leetcode
文章平均质量分 78
hqq39
这个作者很懒,什么都没留下…
展开
-
【leetcode c++】08 String to Integer (atoi)
题目原文:Implement atoi to convert a string to aninteger.实现atoi。 题目虽然只有一句话,但是坑是不少,从填坑的步骤来看,大概会有如下几个隐藏的坑,或者说是硬性规定。【醒目】下面的东西是经过多次提交发现了错误之后总结下来的。有剧透的嫌疑。推荐各位看官先尝试过后再来看。 1、 输入字符串允许有首空格,并且允许有复数个,排原创 2015-06-10 00:17:34 · 481 阅读 · 0 评论 -
【leetcode c++】88 Merge Sorted Array
Merge Sorted ArrayGiven two sorted integer arrays nums1 andnums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space(size that is greater or equal to m原创 2015-07-27 14:27:46 · 1299 阅读 · 0 评论 -
【leetcode c++】101 Symmetric Tree
Symmetric TreeGiven a binary tree, check whether it is amirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric:But the following is not:我相信大家都愿原创 2015-07-27 14:39:02 · 920 阅读 · 0 评论 -
【leetcode c++】100 Same Tree
Same Tree Given two binary trees, write a function tocheck if they are equal or not.Two binary trees are considered equal ifthey are structurally identical and the nodes have the same value.原创 2015-07-27 14:34:06 · 564 阅读 · 0 评论 -
【leetcode c++】107 Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal II Given a binary tree, return the bottom-uplevel order traversal of its nodes' values. (ie, from left to right, level bylevel from leaf to root).For example:原创 2015-07-27 14:46:14 · 445 阅读 · 0 评论 -
【leetcode c++】58 Length of Last Word
Length of Last WordGiven a string s consists ofupper/lower-case alphabets and empty space characters ' ', return the length oflast word in the string.If the last word does not exist, return 0.原创 2015-06-26 22:42:25 · 360 阅读 · 0 评论 -
【leetcode c++】80 Remove Duplicates from Sorted Array II
临近期末,转移战场,考完回家,家里怒报驾校,应接不暇。进正题Remove Duplicates from Sorted Array IIFollow up for "RemoveDuplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array nums = [1,1,原创 2015-07-17 22:54:02 · 543 阅读 · 0 评论 -
【leetcode c++】83 Remove Duplicates from Sorted List
Remove Duplicates from Sorted ListGiven a sorted linked list, delete allduplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return原创 2015-07-17 23:11:35 · 396 阅读 · 0 评论 -
【leetcode c++】82 Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List IIGiven a sorted linked list, delete allnodes that have duplicate numbers, leaving only distinct numbers from theoriginal list. For example,Given1->2->3->3->原创 2015-07-17 23:16:11 · 517 阅读 · 0 评论 -
【leetcode c++】111 Minimum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimumdepth.The minimum depth is the number of nodesalong the shortest path from the root node down to the nearest leaf node. 之前做了原创 2015-07-31 23:23:17 · 326 阅读 · 0 评论 -
【leetcode c++】113 Path Sum II
Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22,ReturnPa原创 2015-08-01 00:06:17 · 1275 阅读 · 0 评论 -
【leetcode c++】 112 Path Sum
Path Sum Given a binary tree and a sum, determine ifthe tree has a root-to-leaf path such that adding upall the values along the path equals the given sum.For example:Given the below binary tr原创 2015-07-31 23:27:31 · 597 阅读 · 0 评论 -
【leetcode c++】160 Intersection of Two Linked Lists
Intersection of Two Linked Lists Write a program to find the node at whichthe intersection of two singly linked lists begins.For example, the following two linkedlists:begin to intersect原创 2015-10-09 17:59:06 · 503 阅读 · 0 评论 -
【leetcode c++】125 Valid Palindrome
Valid Palindrome Given a string, determine if it is apalindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" isa palindrome."r原创 2015-10-09 17:38:52 · 628 阅读 · 0 评论 -
【leetcode c++】155 Min stack
Min stackDesign a stack that supports push, pop,top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack.pop() -- Removes the element on top of thestack.原创 2015-10-09 17:55:04 · 731 阅读 · 0 评论 -
【leetcode c++】102 Binary Tree Level Order Traversal
Binary Tree Level Order TraversalGiven a binary tree, return the level ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,原创 2015-07-27 14:41:16 · 472 阅读 · 0 评论 -
【leetcode c++】104 Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximumdepth.The maximum depth is the number of nodesalong the longest path from the root node down to the farthest leaf node. 给一棵二原创 2015-07-27 14:43:08 · 418 阅读 · 0 评论 -
【leetcode c++】70 Climbing Stairs
Climbing StairsYou are climbing a stair case. It takes nsteps to reach to the top.Each time you can either climb 1 or 2steps. In how many distinct ways can you climb to the top? 高考毒太深,我当作一道{普通原创 2015-06-30 12:31:56 · 452 阅读 · 0 评论 -
【leetcode c++】twoSum
4月份接触leetcode,没多久就要准备考试大坑,已然忘记这玩意。最近得闲,便把已经写好的leetcode整理一下发到博客来。(应该不会出问题吧第一次写博客→ →)先上题目原文Given anarray of integers, find two numbers such that they add up to a specific targetnumber.Thefuncti原创 2015-06-03 15:16:38 · 2360 阅读 · 0 评论 -
【leetcode c++】Reverse Integer
题目很短,也很简单。Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321就是反转整型。从给的例子得出的结论是,只反转数字,不反转符号。在解的过程中,有一个容易忽视的坑:溢出。 思路:也因为输入是一个整型int,要操作里面的每一个数字,首先原创 2015-06-07 19:44:36 · 541 阅读 · 0 评论 -
【leetcode c++】19 removeNthFromEnd
Given a linked list, remove the nth nodefrom the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end,原创 2015-06-16 22:02:30 · 600 阅读 · 0 评论 -
【leetcode c++】14Longest Common Prefix
题目Write a function to find the longest commonprefix string amongst an array of strings.找出一系列字符串的公有前缀。 输入是vector&strs。观察输入,这是一个vector,咋一看是个一维数组。但是,绝大多数情况下,其实里面存的是长短不一的string。因此更像是一个锯齿数组的感觉。原创 2015-06-14 12:19:51 · 559 阅读 · 0 评论 -
【leetcode c++】13 Roman to Integer
题目Given a roman numeral, convert it to aninteger.Input is guaranteed to be within the rangefrom 1 to 3999. 输入一个1-3999的罗马数字(字符串),转化成整型。 首先,我们要大致知道罗马数字。参考百度百科,主要本题要用的资料:基本字符I=1V=5X原创 2015-06-12 12:36:57 · 696 阅读 · 0 评论 -
【leetcode c++】 20 Valid Parentheses
括号匹配。这题,是大学数据结构的题目吧,栈的题目吧(还有魔王语言、迷宫等,有木有)。因为是写过的题目,所以这次直接在leetcode的网页上面写了。还好还记住了思路,一次过~~ Leetcode的Accepted Solutions Runtime Distribution(2015-06-05) 源码:bool isValid(string s){ stack myStac原创 2015-06-18 13:31:38 · 358 阅读 · 0 评论 -
【leetcode c++】21 Merge Two Sorted Lists
Merge two sorted linked lists and return itas a new list. The new list should be made by splicing together the nodes ofthe first two lists.融合两个有序的链表,返回这个新链表。 其实呢,这也是数据结构里面的链表的题(类似多项式的加法),不过稍微比当年原创 2015-06-18 13:37:28 · 998 阅读 · 0 评论 -
【leetcode c++】27 Remove Element
Remove ElementGiven an array and a value, remove allinstances of that value in place and return the new length.The order of elements can be changed. Itdoesn't matter what you leave beyond the new原创 2015-06-22 00:48:04 · 824 阅读 · 0 评论 -
【leetcode c++】ZigZag Conversion
题目原文 The string "PAYPALISHIRING" iswritten in a zigzag pattern on a given number of rows like this: (you may wantto display this pattern in a fixed font for better legibility) P A H NA原创 2015-06-05 00:24:00 · 408 阅读 · 0 评论 -
【leetcode c++】26 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicatesin place such that each element appear only once and return the new length. Do not allocate extra space for anotherarray, you must do this in place with原创 2015-06-20 18:46:19 · 429 阅读 · 0 评论 -
【leetcode c++】66 Plus One
Plus OneGiven a non-negative number represented asan array of digits, plus one to the number.The digits are stored such that the mostsignificant digit is at the head of the list. 一个数字按位存放在一个数组原创 2015-06-26 22:44:35 · 373 阅读 · 0 评论 -
【leetcode c++】28 Implement strStr()
Implement strStr().Returns the index of the first occurrenceof needle in haystack, or -1 if needle is not part of haystack. 实现子字符串查找功能。犹记得清华大学出版社的数据结构书上,那神奇的KMP算法……KMP请自行百度。这里我用了BM算法(只用到了d原创 2015-06-26 22:30:48 · 350 阅读 · 0 评论 -
【leetcode c++】38 Count and Say
Count and SayThe count-and-say sequence is the sequenceof integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is r原创 2015-06-26 22:40:33 · 619 阅读 · 0 评论 -
【leetcode c++】67 Add Binary
Add BinaryGiven two binary strings, return their sum(also a binary string). For example,a = "11"b = "1"Return "100". 二进制大家都知道,这题要求我们给定两个string形式的二进制数字,要我们做加法并返回一个string。有看原创 2015-06-30 12:09:10 · 666 阅读 · 0 评论 -
【leetcode c++】118 Pascal's Triangle
Pascal's Triangle Given numRows, generate the first numRowsof Pascal's triangle.For example, given numRows = 5,Return返回如图示形式的杨辉三角二维数组。数据结构肯定做过的。用二维数组保存的杨辉三角可以是像题目要求那样构造,如下11 11原创 2015-10-09 17:36:50 · 470 阅读 · 0 评论