将一个给定的单链表反转,例:1-2-3-4-5,反转为5-4-3-2-1
示例1
输入
{1,2,3,4,5}
输出
{5,4,3,2,1}
加载中...
import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * } */ public class Solution { /** * * @param head ListNode类 * @return ListNode类 */ public ListNode reverseList (ListNode head) { // write code here } }
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ class Solution { public: /** * * @param head ListNode类 * @return ListNode类 */ ListNode* reverseList(ListNode* head) { // write code here } };
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # # @param head ListNode类 # @return ListNode类 # class Solution: def reverseList(self , head ): # write code here
/* * function ListNode(x){ * this.val = x; * this.next = null; * } */ /** * * @param head ListNode类 * @return ListNode类 */ function reverseList( head ) { // write code here } module.exports = { reverseList : reverseList };
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # # @param head ListNode类 # @return ListNode类 # class Solution: def reverseList(self , head ): # write code here
package main import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ /** * * @param head ListNode类 * @return ListNode类 */ func reverseList( head *ListNode ) *ListNode { // write code here }
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * * @param head ListNode类 * @return ListNode类 */ struct ListNode* reverseList(struct ListNode* head ) { // write code here }
{1,2,3,4,5}
{5,4,3,2,1}