huangjing
链表的合并,要求O(la*lb)的复杂度,实际上就是插入什么的,注意如果在链表开头和结尾的特殊情况
代码
#include
#include
#include
typedef struct node
{
int data;
struct node *next;
}Node,*listnode;
int lena,lenb;
void creatlist(list...
分类:
其他好文 时间:
2014-11-15 12:53:27
阅读次数:
249
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne...
分类:
其他好文 时间:
2014-11-15 00:03:01
阅读次数:
364
以前做过合并数组,这次是合并链表,写起来很快,第一次提交,忘记new一个listNode的时候传参数,导致编译错误,修改完这个错误后就没问题了,代码因该是很简单的。需要注意的是,凡是sorted的,都是从小到大排列,另外leetcode上面的链表都没有尾巴,便利的时候需要注意。 1 /** 2 *....
分类:
其他好文 时间:
2014-11-09 00:59:17
阅读次数:
164
这次是做题最顺的一次,提交两次,耗时1分钟就ac了,错的那次是因为没有考虑到空链表,少了一个判断。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next...
分类:
其他好文 时间:
2014-11-08 07:04:13
阅读次数:
152
class Solution { public: int listSize(ListNode* l){ if(l==NULL) return 0; int len=1; ListNode* p=l; while (p->next...
分类:
其他好文 时间:
2014-11-06 17:23:21
阅读次数:
163
单链表是否有环的问题经常在面试中遇到,一般面试中会要求空间为O(1);再者求若有环,则求环产生时的起始位置。下面采用java实现。//单链表class ListNode{ int val; ListNode next; ListNode(int x){ val...
分类:
编程语言 时间:
2014-11-06 00:35:33
阅读次数:
174
题目描述:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first
two lists.
代码:ListNode * Solution::mergeTwoLists(List...
分类:
其他好文 时间:
2014-10-30 11:44:34
阅读次数:
149
一:题目:给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点。链表结点与函数的定义如下:
struct ListNode
{
int m_nValue;
ListNode* m_pNext;
};
void delete_note(ListNode *head,ListNode *current)
{
// 空的
if(head == null || ...
分类:
编程语言 时间:
2014-10-28 00:53:32
阅读次数:
180
判断一个链表是否为循环链表。 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x...
分类:
其他好文 时间:
2014-10-27 22:49:16
阅读次数:
154
需要额外添加两个相距为n的节点,遍历一遍之后就可以得到结果。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(in...
分类:
其他好文 时间:
2014-10-27 00:21:55
阅读次数:
275