Remove Nth Node From End of List
来源:互联网 发布:中国p2p网贷数据 编辑:程序博客网 时间:2024/04/30 08:37
题目连接:http://www.leetcode.com/onlinejudge
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Try to do this in one pass.
public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { // Start typing your Java solution below // DO NOT write main() function if(head == null) return null; int i = 0; ListNode phead = head; ListNode prevhead = head; while(i++ < n) { phead = phead.next; } while(phead != null && phead.next != null) { head = head.next; phead = phead.next; } if(phead == null) return prevhead.next; head.next = head.next.next; return prevhead; }}
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node from End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- 大小端转换
- 解压uboot1.1.6时的错误tar: uboot1.1.6/include/asm: Cannot create symlink to `asm-arm': Operation not suppo
- 背包问题和0-1背包问题
- Create a basic flowchart
- 常规循环引用内存泄漏和Closure内存泄漏 一些 简单的解决方案
- Remove Nth Node From End of List
- jQuery UI入门手册
- 赵雅智_Java 反射
- PFD - Process Flow Diagram
- MySQL的LAST_INSERT_ID用法
- linux系统管理常用命令--系统信息查询
- Linux 加密工具 gpg base64
- 十六进制、十进制相互转换 VC
- IVR导航语音转换,wav格式转换为gsm