leetcode
weishenmetlc
这个作者很懒,什么都没留下…
展开
-
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 · 273 阅读 · 0 评论 -
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 · 274 阅读 · 0 评论 -
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 · 185 阅读 · 0 评论 -
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 · 215 阅读 · 0 评论 -
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 · 251 阅读 · 0 评论 -
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 · 155 阅读 · 0 评论 -
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 · 249 阅读 · 0 评论 -
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 · 307 阅读 · 0 评论 -
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 · 427 阅读 · 0 评论 -
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 · 184 阅读 · 0 评论 -
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 · 145 阅读 · 0 评论 -
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 · 158 阅读 · 0 评论 -
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 · 153 阅读 · 0 评论 -
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 · 173 阅读 · 0 评论 -
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 · 182 阅读 · 0 评论 -
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 · 151 阅读 · 0 评论 -
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 · 178 阅读 · 0 评论 -
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 · 175 阅读 · 0 评论 -
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 · 231 阅读 · 0 评论 -
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 · 149 阅读 · 0 评论 -
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 · 155 阅读 · 0 评论 -
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 · 173 阅读 · 0 评论 -
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 · 204 阅读 · 0 评论 -
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 · 165 阅读 · 0 评论 -
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 · 174 阅读 · 0 评论 -
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 · 268 阅读 · 0 评论 -
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 · 163 阅读 · 0 评论 -
55:Valid Parentheses
题目:Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]” are all valid bu原创 2017-03-01 23:08:10 · 140 阅读 · 0 评论 -
56:Longest Valid Parentheses
题目:Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (wellformed) parentheses substring. For “(()”, the longest valid parentheses substring is “()”, which原创 2017-03-01 23:11:29 · 153 阅读 · 0 评论 -
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 · 216 阅读 · 0 评论 -
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 · 192 阅读 · 0 评论 -
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 · 246 阅读 · 0 评论 -
57:Evaluate Reverse Polish Notation
题目:Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: [“2”, “1”, “+”, “3”原创 2017-03-02 23:56:09 · 532 阅读 · 0 评论 -
1: Remove Duplicates from Sorted Array
注:本题的解法思想来自于https://github.com/soulmachine/leetcode#leetcode题解题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate原创 2017-02-15 22:36:47 · 173 阅读 · 0 评论 -
2:Remove Duplicates from Sorted Array II
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:Follow up for ”Remove Duplicates”: What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3原创 2017-02-15 22:44:27 · 196 阅读 · 0 评论 -
3:Search in Rotated Sorted Array
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Y原创 2017-02-15 22:49:39 · 168 阅读 · 0 评论 -
4:Search in Rotated Sorted Array II
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:Follow up for ”Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How an原创 2017-02-15 23:03:18 · 193 阅读 · 0 评论 -
5: Median of Two Sorted Arrays
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time原创 2017-02-15 23:08:05 · 176 阅读 · 0 评论 -
6: Longest Consecutive Sequence
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4,原创 2017-02-15 23:13:33 · 145 阅读 · 0 评论 -
7: two sum
注:本题的解法思想及参考的代码来自于https://github.com/soulmachine/leetcode#leetcode题解题目:Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return原创 2017-02-15 23:19:45 · 211 阅读 · 0 评论