class Solution { public: ListNode *reverseKGroup(ListNode *head, int k) { if (!head || !(head->next) || k < 2) return head; // count k nodes ListNode *nextgp = head; for (int i = 0; i < k; i++) if (nextgp) nextgp = nextgp->next; else return he…
我用String代替了链表显示,本题的大意是每k个进行逆序处理,剩下的不够k个的就按照原顺序保留下来. public class ReverseNodes { public static void main(String[] args) { String str = "1->2->3->4->5->6->7->8->9->10->11->12->13->14->15"; String[] strArra…
Total Accepted: 48614 Total Submissions: 185356 Difficulty: Hard 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 rem…
9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra…
错误日志 Diagnostic Messages for this Task: Error: java.io.IOException: java.io.IOException: java.io.EOFException: Read past end of RLE integer from compressed stream Stream for column 1 kind LENGTH position: 359 length: 359 range: 0 offset: 212849 limit…
一.Reverse Linked List  (M) Reverse Linked List II (M) Binary Tree Upside Down (E) Palindrome Linked List /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class…
1. Reverse Linked List 题目链接 题目要求: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? 初想用递归来实现应该会挺好的,但最终运行时间有点久,达到72ms,虽然没超时.具体程序如下: /** * Definition for singly-linked list. *…
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up:Could you do it in O(n) time and O(1) space? Sloving with O(3n) -> O(n) Idea: reversing th…
http://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream> #include <m…
[抄题]: We are given a binary tree (with root node root), a target node, and an integer value K. Return a list of the values of all nodes that have a distance K from the target node.  The answer can be returned in any order. Example 1: Input: root = [3…