leetcode Remove Nth Node From End of List(Java)
来源:互联网 发布:愚人节整人软件 编辑:程序博客网 时间:2024/05/24 04:57
题目链接:点击打开链接
类型:Remove Nth Node From End of List
解法:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) {ListNode before = head;int len = 0;while (before != null){before = before.next;len++;}if (len == n)return head.next;if (len == 2){if (n == 2)return head.next;else{ListNode s = new ListNode(head.val);s.next = null;}}before = head;int j = 1;while(j < len-n){before = before.next;j++;}ListNode temp = before.next.next;before.next = temp;return head; }}
阅读全文
0 0
- [Leetcode] Remove Nth Node From End of List (Java)
- [LeetCode][Java] Remove Nth Node From End of List
- leetcode oj java Remove Nth Node From End of List
- LeetCode 19 : Remove Nth Node From End of List (Java)
- LeetCode : Remove Nth Node From End of List [java]
- leetcode:Remove Nth Node From End of List 【Java】
- Leetcode:19. Remove Nth Node From End of List(JAVA)
- Remove Nth Node From End of List leetcode java
- LeetCode – Remove Nth Node From End of List (Java)
- [LeetCode-Java]19. Remove Nth Node From End of List
- [LeetCode] 19. Remove Nth Node From End of List java
- leetcode Remove Nth Node From End of List(Java)
- Remove Nth Node From End of List leetcode java
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- CI对数据库的常用操作
- linux中的ldd命令简介
- Ubuntu 16.04 蓝牙
- CountDownLatch使用场景
- 计算机网络基础(一)
- leetcode Remove Nth Node From End of List(Java)
- Form表单值为空和数据库模糊查询的处理问题
- laravel--6 eloquent查询作用域
- 关于树莓派下调用百度语音合成REST API说明
- centos6.7安装jdk7
- 金融系统中的还款日计算(自用虽然比较low)
- Ubuntu U盘装
- Maven私服Nexus3.x环境构建操作记录
- 撰写一组SNORT规则防御SQL注入