LeetCode
来源:互联网 发布:淘宝网拍 编辑:程序博客网 时间:2024/05/22 09:01
Q:
Reverse a singly linked list.
Hint:
A linked list can be reversed either iteratively or recursively. Could you implement both?
A:
# Definition for singly-linked list.class ListNode(object): def __init__(self, x): self.val = x self.next = Noneclass Solution(object): def reverseList(self, head): """ :type head: ListNode :rtype: ListNode """ pre = None while head: current = head head = head.next current.next = pre pre = current return pre
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- Java SE 基础(一)
- Unity Shader-渲染队列,ZTest,ZWrite,Early-Z
- webstrom:使用js无法指定路径问题
- Qual_A:传话游戏
- 遇到的面试问题总结
- LeetCode
- jupyter notebook 的工作空间设置
- PAT_A 1047. Student List for Course (25)
- DHTML(Dynamic HTML)--1表格的增删改
- Maven-入门案例
- 九度[1465]-最简真分数
- Window系统Apache2.4+Tomcat7.0整合配置
- KD树
- Ubuntu16.04安装nvidia中的一些坑