摘要: ☆☆思路:栈 + 头插法。本题要求不能对节点进行翻转,那么对于逆序处理,首先应该想到数据结构【栈】。 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { // 不能对节点进行翻转,故用到数据结构【栈】 阅读全文
posted @ 2020-12-13 19:34 不学无墅_NKer 阅读(66) 评论(0) 推荐(0) 编辑
摘要: ☆☆☆解法:考虑进位值 以及 较短的链表补0 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode dummyHead = new ListNode(0); ListNode cur = 阅读全文
posted @ 2020-12-13 18:47 不学无墅_NKer 阅读(58) 评论(0) 推荐(0) 编辑
摘要: 思路1:类似LeetCode86. 分隔链表,设置两个虚拟头节点,最后拼接即可。 ☆☆思路2:分离节点后合并,不需要设置虚拟头节点 class Solution { public ListNode oddEvenList(ListNode head) { if (head == null || he 阅读全文
posted @ 2020-12-13 17:34 不学无墅_NKer 阅读(48) 评论(0) 推荐(0) 编辑
摘要: ☆☆思路:要设置两个虚拟头节点 class Solution { public ListNode partition(ListNode head, int x) { if (head == null || head.next == null) return head; ListNode smallD 阅读全文
posted @ 2020-12-13 16:54 不学无墅_NKer 阅读(71) 评论(0) 推荐(0) 编辑
摘要: ☆☆解法 class Solution { public ListNode deleteDuplicates(ListNode head) { if (head == null || head.next == null) return head; ListNode cur = head; while 阅读全文
posted @ 2020-12-13 16:27 不学无墅_NKer 阅读(63) 评论(0) 推荐(0) 编辑
摘要: ☆☆☆思路:虚拟头节点 + 反转链表 class Solution { public ListNode reverseBetween(ListNode head, int m, int n) { if (head == null || head.next == null || m == n) ret 阅读全文
posted @ 2020-12-13 15:24 不学无墅_NKer 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 方法1:迭代反转链表。 ☆☆☆方法2:递归反转链表。 class Solution { // ListNode pre = null, next = null; // 方法3全局变量 public ListNode reverseList(ListNode head) { /** * 方法1:迭代法 阅读全文
posted @ 2020-12-13 10:33 不学无墅_NKer 阅读(92) 评论(0) 推荐(0) 编辑