Title:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. Af...
分类:
其他好文 时间:
2015-04-13 09:27:27
阅读次数:
88
本题比较简单,主要考察了单链表的创建与删除。
但是有一个问题需要着重的考虑,如何快速定位链表的倒数第n个节点。这就需要两个辅助节点,一个节点先走到正数第n个位置,然后两个辅助节点一块往后走,最后后面的节点的位置就是我们需要的倒数第n个节点。#include
#include
struct ListNode//定义节点
{
int value;
struct ListNode *ne...
分类:
其他好文 时间:
2015-04-12 22:49:42
阅读次数:
236
io的使用 1 package com.tan.io; 2 3 import java.io.*; 4 import java.util.*; 5 6 class Employee{ 7 private String name; 8 private double salary; ...
分类:
编程语言 时间:
2015-04-12 19:09:13
阅读次数:
182
Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re...
分类:
其他好文 时间:
2015-04-12 17:44:42
阅读次数:
118
The Employee table holds all employees. Every employee has an Id, a salary,
and there is also a column for the department Id.
+----+-------+--------+--------------+
| Id | Name | Salary | Departme...
分类:
其他好文 时间:
2015-04-12 16:18:06
阅读次数:
125
The Employee table holds all employees including their managers. Every employee
has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+
| Id | Name | Salary |...
分类:
其他好文 时间:
2015-04-12 14:49:10
阅读次数:
118
Write a SQL query to get the second highest salary from the Employee table.
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For exa...
分类:
其他好文 时间:
2015-04-12 00:08:47
阅读次数:
191
1 /** 2 * ID: 19 3 * Name: Remove Nth Node From End of List 4 * Data Structure: Linked List 5 * Time Complexity: 6 * Space Complexity: ...
分类:
其他好文 时间:
2015-04-11 16:06:16
阅读次数:
139
删除链表倒数第n个节点,返回链表。要求在一趟遍历中完成。【思路】两个指针,初始都指向head。p向下遍历,当遇到第n-1个节点时,q开始向下遍历,这样当p走到最后一个节点,q所指就是要删除的节点。另需一个pre指针指向q的前一个节点,删除时pre->next=q->next。【my code】Lis...
分类:
其他好文 时间:
2015-04-09 10:20:58
阅读次数:
109
题目连接:https://leetcode.com/problems/remove-nth-node-from-end-of-list//** * Definition for singly-linked list. * struct ListNode { * int val; * ...
分类:
其他好文 时间:
2015-04-07 19:34:12
阅读次数:
95