[leetCode Summary] LinkedList

几个套路

第一 fast slow 找中点,找位数。

第二 reverse

{

ListNode last = prev.next;

ListNode curr = last.next;

while(curr!=null)

{

last.next = curr.next;

curr.next = prev.next;

prev.next = curr;

curr = last.next;

}

}

第三搞两个linkedlist然后连起来

时间: 2024-08-09 23:54:55

[leetCode Summary] LinkedList的相关文章

[LeetCode] Summary Ranges 总结区间

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. Credits:Special thanks to @jianchao.li.fighter for adding this problem and

LeetCode -- Summary Ranges

题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. Credits:Special thanks to @jianchao.li.fighter for adding this probl

LeetCode——Summary Ranges

Description: Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 确定有序数组的区间 需要注意各种边界细节,每次确定区间之后需要清空. public class Solution { pu

[leetcode summary] Dynamic Programming

套路: 一般有两个string的时候 都建二维的数组来存. int[][] dp =new int[len+1][len+1]; 初始情况已设立 dp[0][0] = 1; 递归循环 for() dp[i][j] = dp [i-1][j]; 交答案 dp[len][len]

[leetcode summary] Backtracing

主线是 res helper(res):dfs(): helper(res,num,curr, index, resultOne, visited..) { if(curr==num) 1 res.add(resultOne); 2 res.add(new resultOne); else { for() { if() 1: temp = new resultOne helper(temp...) 2 result.add(); visited; helper(); result.remove(

LeetCode:Reverse LinkedList

problem: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? solution:头插法逆转链表 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListN

LeetCode Summary Ranges (统计有序数列范围)

题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列. 思路:找每个范围的起始和结束即可. 1 class Solution { 2 public: 3 vector<string> summaryRanges(vector<int>& nums) { 4 if(nums.empty()) return vector<string>(); 5 vector<string> vect; 6 for(int i=0; i<nums.size

[leetcode Summary] BFS

BFS有固定的套路 类似下面这个形式 ArrayList<String> queue = new ArrayList<String>(); queue.add(root); while(!queue.isEmpty()) { String temp = queue.poll(); for(neigbor : temp) { queue.add(); } }

LeetCode:Reverse LinkedListⅡ

Problem: 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. Note: Given m, n satisfy the following condition: 1 ≤ m