- 博客(55)
- 收藏
- 关注
原创 54: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 defi
2017-02-28 22:20:27 163
原创 53:Simplify Path
题目:Given an absolute path for a file (Unix-style), simplify it. For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” Corner Cases: • Did you consider the case where path = “/
2017-02-28 22:17:42 153
原创 52:Anagrams
题目:Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case.解析:anagram 表示由颠倒字母顺序而构成的单词。属于 anagram 的两个字符串虽然它们的字母顺序不同,但是将它们按字母排序后应该相等,否则这两个字符串就不属
2017-02-28 22:14:19 193
原创 51:Count and Say
题目:The count-and-say sequence is the sequence of 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 read off as “one 2
2017-02-28 22:01:44 162
原创 50:Roman to Integer
题目:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.下面解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目题目解析:从前往后扫描字符串,逐个字符的扫
2017-02-28 21:57:33 146
原创 49 : Integer to Roman
题目:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.在解题之前,最好要先了解一下罗马数字组合原理罗马数字:罗马数字采用 7 个罗马字母作数字,即 I(1),V(5),X(10),L(50),C(100),D(500),M(100
2017-02-28 21:50:05 139
原创 48:Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings此题比较简单,解题代码如下:// 时间复杂度 O(n1 + n2 + ...)class Solution {public: string longestCommonPrefix(vector<string
2017-02-27 08:59:55 165
原创 47:Wildcard Matching
题目:Implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence). The matching should cover
2017-02-26 23:03:07 159
原创 46:Regular Expression Matching
题目:Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input
2017-02-26 13:39:23 220
原创 45:Longest Palindromic Substring
题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.解析1(解法代码的思想及编写参考了网址http
2017-02-24 18:41:41 170
原创 44:Implement strStr()
题目:Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.解题代码如下(本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetco
2017-02-24 18:29:27 155
原创 43:Add Binary
题目:Given two binary strings, return their sum (also a binary string). For example, a = “11” b = “1” Return “100”.解题代码如下:class Solution {public: string addBinary(string a, string b) {
2017-02-22 20:30:40 235
原创 42:String to Integer (atoi)
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目 题目:Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge,
2017-02-22 19:57:33 182
原创 41:Valid Palindrome
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目题目:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, “A m
2017-02-22 09:04:54 208
原创 40:LRU Cache
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目题目:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and s
2017-02-20 21:41:25 155
原创 39:Reorder List
题目:Given a singly linked list L : L0−>L1−>...−>Ln−1−>LnL_{0} -> L_{1} -> ... -> L_{n - 1} -> L_{n} , reorder it to: L0−>Ln−>L1−>Ln−1−>L2−>Ln−2−>L_{0} -> L_{n} -> L_{1} -> L_{n -1} -> L_{2} -> L_{
2017-02-20 20:20:41 261
原创 38:Linked List Cycle II
题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space?解析1:下面解题代码的思想及编写参考了网址https://github.com/soulmac
2017-02-20 10:35:56 225
原创 37:Linked List Cycle
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目题目:Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?解析1:设置一个快指针和一个慢指针,
2017-02-20 09:49:20 166
原创 36:Copy List with Random Pointer
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
2017-02-19 22:55:05 169
原创 35:Reverse Nodes in k-Group
题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2017-02-19 21:44:23 144
原创 34:Swap Nodes in Pairs
题目:Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You
2017-02-19 21:03:24 173
原创 33:Remove Nth Node From End of List
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5,
2017-02-19 20:11:32 164
原创 32:Rotate List
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->nullptr and k =
2017-02-19 14:21:19 145
原创 31:Remove Duplicates from Sorted List II
本题解法代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Fo
2017-02-18 00:38:16 151
原创 30:Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.解题代码版本一://迭代版本//时间复杂度O(n),
2017-02-18 00:25:16 138
原创 29:Partition List
题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each o
2017-02-17 18:07:39 174
原创 28:Reverse Linked List II
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->nullptr, m = 2 and n
2017-02-17 15:04:57 302
原创 27:Reverse Linked List
题目:Reverse a singly linked list.解题代码如下://迭代版// reversed the whole linked list// 时间复杂度 O(n),空间复杂度 O(1)class Solution {public: ListNode* reverseList(ListNode* head) { if (head
2017-02-17 15:00:56 418
原创 26: Add Two Numbers
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their node
2017-02-17 11:47:48 238
原创 25 : Single Number III
题目: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. For example: Given num
2017-02-16 22:52:30 145
原创 24:Single Number II
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should ha
2017-02-16 21:38:24 245
原创 23:Single Number
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a l
2017-02-16 21:34:26 206
原创 22: Candy
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected
2017-02-16 20:27:23 177
原创 21: Gas Station
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited
2017-02-16 19:35:28 263
原创 20 : Set Matrix Zeroes
注:本题的解法思想及代码参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目:Given a m n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space?
2017-02-16 15:14:44 264
原创 19:Gray Code
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n repres
2017-02-16 00:13:47 174
原创 18:Climbing Stairs
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many dis
2017-02-16 00:06:04 155
原创 17:Plus One
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:Given a number represented as an array of digits, plus one to the number代码如下://时间复杂度O(n),空间复杂度O(1)class Solution {public:
2017-02-16 00:02:25 223
原创 16: Rotate Image
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:You are given an n n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this
2017-02-16 00:01:12 175
原创 15:Trapping Rain Water
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able t
2017-02-15 23:58:30 185
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人