1 public boolean hasCycle(ListNode head) { 2 ListNode s=head; 3 ListNode f=head; 4 while(f!=null&&f.next!=null){ 5 ...
分类:
其他好文 时间:
2014-07-31 16:14:27
阅读次数:
223
1 public ListNode detectCycle(ListNode head) { 2 ListNode s=head; 3 ListNode f=head; 4 while(f!=null&&f.next!=null){ 5 ...
分类:
其他好文 时间:
2014-07-31 16:01:36
阅读次数:
167
Just corner case..class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { if(m == n) return head; ListNode *...
分类:
其他好文 时间:
2014-07-31 09:34:05
阅读次数:
245
直接递归
代码:
#include
#include
using namespace std;
typedef struct listNode{
int key;
struct listNode *pNext;
} * pNode,Node;
void createNode(pNode &pHead){
bool isFirst=true;
int temp;
sc...
分类:
其他好文 时间:
2014-07-30 20:57:14
阅读次数:
174
1 package leetcode; 2 3 public class DetectCycle { 4 public ListNode detectCycle(ListNode head) { 5 ListNode s=head; 6 ListNode ...
分类:
其他好文 时间:
2014-07-30 20:20:04
阅读次数:
243
1 package leetcode; 2 3 public class ReOrderList { 4 public void reorderList(ListNode head) { 5 if(head==null||head.next==null||head.ne...
分类:
其他好文 时间:
2014-07-30 20:05:54
阅读次数:
243
使用数据结构stack或者递归
1 使用stack
#include
#include
using namespace std;
typedef struct listNode{
int key;
struct listNode *pNext;
} * pNode,Node;
void createNode(pNode &pHead){
bool isFirst=true;...
分类:
其他好文 时间:
2014-07-30 17:30:34
阅读次数:
189
归并排序的链表法#includeusing namespace std;struct ListNode{ int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution{public:...
分类:
其他好文 时间:
2014-07-30 07:40:23
阅读次数:
174
Sort a linked list using insertion sort.题目要求:链表的插入排序,由于没有时间复杂度的要求,可以直接循环操作。/** * Definition for singly-linked list. * struct ListNode { * int val;...
分类:
其他好文 时间:
2014-07-29 10:54:26
阅读次数:
190
解法:比较简单,用plus表示进位 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(in...
分类:
其他好文 时间:
2014-07-29 10:53:06
阅读次数:
273