描述 给定一个链表,判断它是否有环。 样例 给出 -21->10->4->5, tail connects to node index 1,返回 true。 这里解释下,题目的意思,在英文原题中,tail connects to node index 1 表示的是节点 5 还要链接回索引号 为 1 ...
分类:
其他好文 时间:
2018-12-16 14:41:38
阅读次数:
127
Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no ...
分类:
其他好文 时间:
2018-12-15 11:48:51
阅读次数:
117
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: 只反转从m到n的部分链表 M1: iterative 首先找到prev的位置(开始反转位 ...
分类:
其他好文 时间:
2018-12-15 10:30:47
阅读次数:
165
problem 206. Reverse Linked List 参考 1. Leetcode_Reverse Linked List; 完 ...
分类:
其他好文 时间:
2018-12-14 10:56:29
阅读次数:
132
这是悦乐书的第 196 次更新,第 202 篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第58题(顺位题号是234)。给出一个单链表,确定它是否是回文。例如: 输入:1 2 输出:false 输入:1 2 2 1 输出:true 本次解题使用的开发工具是eclipse ...
分类:
编程语言 时间:
2018-12-09 14:14:51
阅读次数:
198
这是悦乐书的第 189 次更新,第 191 篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第48题(顺位题号是203)。移除单链表中节点值为val的节点。例如: 输入:1 2 6 3 4 5 6,val = 6 输出:1 2 3 4 5 本次解题使用的开发工具是ecli ...
分类:
编程语言 时间:
2018-12-02 12:24:55
阅读次数:
184
https://leetcode.com/problems/remove-linked-list-elements/ Remove all elements from a linked list of integers that have value val. Example: 递归代码: /** ...
分类:
其他好文 时间:
2018-11-30 13:59:44
阅读次数:
112
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->2 Output: 1->2 Example 2: Input: 1- ...
分类:
其他好文 时间:
2018-11-29 15:19:09
阅读次数:
162
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solu... ...
分类:
其他好文 时间:
2018-11-24 16:43:21
阅读次数:
171
一、题目 1、审题 2、分析 一个长度为 n+1 的整形数组,元素值为 1~ n 之间。其中一个元素重复了多次,其他元素只出现一次。求出多次出现的那个元素。 二、解答 1、思路 类似: 142. Linked List Cycle II //这道题的关键在于0处是没有索引指向的,将数组视为静态链表, ...
分类:
其他好文 时间:
2018-11-23 22:54:07
阅读次数:
170