Leetcode
_Dre
为什么想要坚持最后却选择放弃
展开
-
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.class Solution {public: Lis原创 2017-02-27 13:25:30 · 155 阅读 · 0 评论 -
Linked List Cycle
链表题 Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?快慢指针class Solution {public: bool hasCycle(ListNode *head) { ListNode *fir原创 2017-02-27 13:39:25 · 148 阅读 · 0 评论 -
Linked List Cycle II
链表题 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. 一开始不知道思路,后来看快慢指针里给出了大概思路 class Solution {public: ListNode *detectCycle(ListNode *head) {原创 2017-02-27 14:10:09 · 154 阅读 · 0 评论 -
Delete Node in a Linked List
链表题 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 third node with value原创 2017-02-27 14:18:44 · 173 阅读 · 0 评论 -
Intersection of Two Linked Lists
链表题 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 ↘原创 2017-02-27 14:52:55 · 196 阅读 · 0 评论 -
Remove Linked List Elements
链表题 Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5 思路: 加一个头节点,就比较好操作了class Solution {原创 2017-02-27 14:59:48 · 142 阅读 · 0 评论 -
Reverse Linked List
链表题 Reverse a singly linked list. 翻转链表 习惯加一个头节点比较好写class Solution {public: ListNode* reverseList(ListNode* head) { ListNode newHead(0); newHead.next = head; ListNode *cu原创 2017-02-27 15:07:58 · 160 阅读 · 0 评论 -
Palindrome Linked List
链表题 Given a singly linked list, determine if it is a palindrome. 判断链表是否回文 想法是遍历一遍入栈,然后再遍历一遍,比较即可class Solution {public: bool isPalindrome(ListNode* head) { std::stack<int> res;原创 2017-02-27 15:26:44 · 151 阅读 · 0 评论