牛客题霸-算法篇
重排链表
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
热度指数:78712
本题知识点:
链表
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
将给定的单链表
:
重新排序为:
要求使用原地算法,不能改变节点内部的值,需要对实际的节点进行交换。
例如:
对于给定的单链表{10,20,30,40},将其重新排序为{10,40,20,30}.
说明:本题目包含复杂数据结构ListNode,
点此查看相关信息
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public void reorderList(ListNode head) { } }
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: void reorderList(ListNode *head) { } };
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # # @param head ListNode类 # @return void # class Solution: def reorderList(self , head ): # write code here
/* * function ListNode(x){ * this.val = x; * this.next = null; * } */ /** * * @param head ListNode类 * @return void */ function reorderList( head ) { // write code here } module.exports = { reorderList : reorderList };
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # # @param head ListNode类 # @return void # class Solution: def reorderList(self , head ): # write code here
package main import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ /** * * @param head ListNode类 * @return void */ func reorderList( head *ListNode ) { // write code here }
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * * @param head ListNode类 * @return void */ void reorderList(struct ListNode* head ) { // write code here }