题目链接区间合并,贪心,需要注意边界情况,LeetCode的数据还是比较好的,这样才能写出健壮的程序。附上代码:
1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 *
in...
分类:
其他好文 时间:
2014-05-06 00:16:44
阅读次数:
400
Given two binary strings, return their sum
(also a binary string).For example,a ="11"b
="1"Return"100".思路:一个二进制字符串相加;首先从字符串的末尾开始,先二进制字符转化为数字,然后再相加;然后将...
分类:
其他好文 时间:
2014-05-05 23:10:15
阅读次数:
319
遇到的问题:input{1,1,1}, output{1,1}, expected{1},
原因在于若temp.val==temp.next.val, 则需要temp.next=temp.next.next,
这时候就不要temp=temp.next了注意停止条件不光是temp!=null,还应该有...
分类:
其他好文 时间:
2014-05-05 22:47:08
阅读次数:
454
Link:http://oj.leetcode.com/problems/swap-nodes-in-pairs/Given a linked list,
swap every two adjacent nodes and return its head.For example,Given1->2-...
分类:
其他好文 时间:
2014-05-05 22:45:37
阅读次数:
331
Problem
Link:http://oj.leetcode.com/problems/word-ladder/Two typical techniques are
inspected in this problem:Hash Table. One hash set is the words di...
分类:
其他好文 时间:
2014-05-05 22:44:44
阅读次数:
393
void Merge(int A[],int p,int q,int r){
int i,j,k;
//计算子数组A[p..q]的元素个数
int n1 = q - p + 1;
//计算子数组A[q+1..r]元素个数
int n2 = r - q;
//创建子数组L,R
int* L = (int*)malloc(sizeof(int)*...
分类:
其他好文 时间:
2014-05-04 12:44:38
阅读次数:
384
Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear in the second line, three in the third line, etc. Develop a program which will compute the largest ...
分类:
其他好文 时间:
2014-05-03 17:32:22
阅读次数:
284
$.方法
(1)$.merge(first, second)
合并两个数组或类数组,将第二个数组添加到第一个数组的末尾
(2)$.grep(elems, callback, invert)
使用callback对elems进行过滤,如果invert设置为true.则返回保留callback返回值为false的元素数组,如果invert设置为false则返回c...
分类:
Web程序 时间:
2014-05-03 16:37:05
阅读次数:
333
The game of billiards involves two players knocking 3 balls around
on a green baize table. Well, there is more to it, but for our
purposes this is sufficient.
The game consists of several rounds ...
分类:
其他好文 时间:
2014-05-03 16:15:33
阅读次数:
296
本题就是测试读入数据的速度的。
如果有大量的数据读入,使用cin是很慢的。
那么使用scanf那么会快很多,但是如果数据量更大的话那么就还是不够快了。
所以这里使用fread。
首先开一个buffer,然后使用fread大块大块地读入数据就可以非常快地读入了。
题目如下:
Input
The input begins with two positive...
分类:
其他好文 时间:
2014-05-03 16:13:21
阅读次数:
340