
leetcode
大芝士球
一个平凡人心中的波澜壮阔
展开
-
206. Reverse Linked List (单链表的逆置)
Description:Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both? 使用迭代和递归的方法实现单链表的逆置我们追求不仅仅是实现单链表的逆置,而是就...原创 2018-02-25 21:56:31 · 307 阅读 · 0 评论 -
349. Intersection of Two Arrays (sort) c++ (map方法需学习)
Description:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The result ca...原创 2018-03-11 16:28:23 · 247 阅读 · 0 评论 -
242. Valid Anagram (sort) c++
Decsription:Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may assum...原创 2018-03-11 14:58:40 · 161 阅读 · 0 评论 -
19. Remove Nth Node From End of List (删除尾部开始计数的结点) Review
Description: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, and n = 2. After removing the second node...原创 2018-03-03 21:12:12 · 127 阅读 · 0 评论 -
1. Two Sum (to be continue~~~~)
Description:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use...原创 2018-02-24 19:04:21 · 149 阅读 · 0 评论 -
148. Sort List 分治法解决 (Review)
Description:Sort a linked list in O(n log n) time using constant space complexity.对链表排序,时间复杂度的要求是O(n log n),空间复杂度的要求比较模糊但尽量占用更少的空间就没错算法思路:看见这个时间复杂度的要求我们就会想到高级排序,故可以使用分治策略。先将链表一分为二,再递归调用sort函数不断地分割链表直至...原创 2018-03-16 17:09:46 · 175 阅读 · 0 评论 -
328. Odd Even Linked List
Description:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to ...原创 2018-03-09 17:54:30 · 142 阅读 · 0 评论 -
203. Remove Linked List Elementss
Description:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --...原创 2018-03-09 17:05:26 · 172 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II (Review)
Description:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, retu...转载 2018-03-15 16:53:46 · 111 阅读 · 0 评论 -
160. Intersection of Two Linked Lists (两链表的交结点) Review
Description:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ ...原创 2018-03-01 11:50:22 · 169 阅读 · 0 评论 -
141. Linked List Cycle (循环链表)
Description:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?确定给出的链表是否是循环链表,不使用额外的空间算法思路:用快慢指针法,如果快慢指针相遇了,说明是循环链表bool hasCycle(struct ListNod...原创 2018-03-01 11:00:18 · 155 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List (删除重复结点)
Description: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-&g...原创 2018-02-28 21:34:09 · 188 阅读 · 0 评论 -
21. Merge Two Sorted Lists (合并两个链表) Review
Description:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Out...原创 2018-02-27 21:31:24 · 130 阅读 · 0 评论 -
237. Delete Node in a Linked List (删除结点)
Description:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the thir...原创 2018-02-27 21:09:51 · 167 阅读 · 0 评论 -
234. Palindrome Linked List (判断回文链表)
Description:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?判断一个链表是否是回文链表注意条件......算法思考:1.先用一个数组存储正向的链表的每一个结点的值,再使用单链表的就地逆置 ,用另一个数组存储逆...原创 2018-02-26 21:59:31 · 146 阅读 · 0 评论 -
92. Reverse Linked List II (Review)
Description: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->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.N...原创 2018-03-17 17:45:31 · 149 阅读 · 0 评论