摘要: 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... 阅读全文
posted @ 2014-09-16 13:35 LeviCode 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
posted @ 2014-09-16 11:58 LeviCode 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 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.思路:增加一个头指... 阅读全文
posted @ 2014-09-15 21:38 LeviCode 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2014-09-15 15:04 LeviCode 阅读(77) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 1 /** 2 * Definition for singly-linked l... 阅读全文
posted @ 2014-09-11 21:44 LeviCode 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2014-09-11 20:57 LeviCode 阅读(97) 评论(0) 推荐(0) 编辑
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 罗马数字有如下符号:罗马字符: I V X L C D M对应数字... 阅读全文
posted @ 2014-09-11 20:41 LeviCode 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 1. 求幂#include //头文件 pow(a,b); //a^b2. bool#include //C中使用bool型需要加入头文件3. 字符串操作相关#include //头文件 char a[20],b[20]; strcpy(a,b); //把字符串b拷贝到a中 length=s... 阅读全文
posted @ 2014-08-21 00:38 LeviCode 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 八月初心血来潮,花了一天时间写了一个控制台版的2048。代码很烂,玩到后面会有延迟现象。先做下记录,以后有时间把移动和合并的代码再优化下。 代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 using n... 阅读全文
posted @ 2014-08-20 23:58 LeviCode 阅读(218) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-07-26 17:35 LeviCode 阅读(133) 评论(0) 推荐(0) 编辑