JS部分/*删除当前的索引行,从后往前删*/ function removeModel(count) { var o = confirm("确认删除?"); if (o) { var i ...
分类:
Web程序 时间:
2014-07-13 11:53:40
阅读次数:
275
题目
Sort a linked list using insertion sort.
解答
链表无法像数组那样从后往前依次比较插入,只能从前往后;在链表首部添加一个哨兵可以稍微简化下代码,代码如下:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ...
分类:
其他好文 时间:
2014-07-11 08:06:49
阅读次数:
362
题意:给你n个点m条边,问删除前i条边后有多少个连通分块。
思路:从后往前操作,从后往前添加i条边等于添加完m条边后删掉前m-i条边,可知刚开始没有边,所以sum[m]=n;
#include
#include
#include
#include
#include
#include
#define M 100010
#define LL...
分类:
其他好文 时间:
2014-06-30 20:26:50
阅读次数:
198
题意:给你初始4个数字和目标4个数字,问是否能由初始经过变换到目标数字;
变换规则:每个数字可以加1(9+1=1)或减1(1-1=9),或交换相邻的数字(最左和最右不是相邻的)。
双向广搜:分别对初始和目标数字进行广搜,vis数组用1和2标记两种已搜索的数字,用mp数组记录状态的步数。
当从前往后搜可以到达2或从后往前搜可以到达1状态则就可以了。。。
#in...
分类:
其他好文 时间:
2014-06-22 19:38:26
阅读次数:
231
2 8 5 3 11.从后往前,找到第一个逆序的数
pivot2.从后往前,找到第一个比pivot大的数 change3.交换 pivot 和 change的值4.把pivot这个位置后面的数
reverse,就是 8 5 2 1变成 1 2 5 8最终为3 1 2 5 8#include #inc...
分类:
其他好文 时间:
2014-06-13 17:38:19
阅读次数:
378
题目:
Given two sorted integer arrays A and B, merge B into A as one sorted array.
原题链接(点我)
解题思路:
合并两个数组为一个有序数组,这题也很简单,唯一考查的地方就是怎么处理数组,是从前往后还是从后往前。一般情况,从后往前的效率比从前往后高,也要省不少事。代码如下,从后开始合并。
代码实现:...
分类:
其他好文 时间:
2014-06-11 00:37:42
阅读次数:
314
题目
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100".
方法
从后往前,每个字符进行判断。
public String addBinary(String a, String...
分类:
其他好文 时间:
2014-06-10 17:50:48
阅读次数:
241
题目
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
方法
从后往前求解...
分类:
其他好文 时间:
2014-06-10 07:38:21
阅读次数:
171
【题目大意】给你一个sum和一个limit,现在要你在1~limit中找到一些数来使得这些数的和等于sum,如果能找到的话就输出找到的数的个数和这些数,未找到输出"-1"。比赛的时候被hack了。【题目分析】这题需要将所有的数的lowbit先求出来,然后按照大小排序,然后从后往前判断,如果这个数小于...
分类:
其他好文 时间:
2014-06-05 20:36:44
阅读次数:
307
比起POJ弱爆了一题,从后往前扫描一遍,O(n)时间,只要注意各种极端情况即可,不明白通过率为什么只有13%。
#include
#include
using namespace std;
class Solution {
public:
void reverseWords(string &s) {
char* cstr = new char[s.size()+1];
...
分类:
其他好文 时间:
2014-06-05 03:45:47
阅读次数:
221