#include
using namespace std;
int calZeroNum(int num)
{
if (0 == num)
{
return 0;
}
int count = 0;
while (0 != num)
{
if (0 == (num & 1))
{
...
分类:
其他好文 时间:
2015-01-05 16:46:48
阅读次数:
111
#include
using namespace std;
int main()
{
int N = 0;
while(cin>>N)
{
int *students = new int [N + 1];//students[0]保留不用
memset(students, 1, sizeof(int) * (N +1...
分类:
其他好文 时间:
2015-01-05 16:41:34
阅读次数:
115
#include
#include "OJ.h"
using namespace std;
/*
Description
给定一个字符串,将字符串中所有和前面重复多余的字符删除,其余字符保留,输出处理后的字符串。需要保证字符出现的先后顺序。
Prototype
int GetResult(const char *input, char *output)
I...
分类:
其他好文 时间:
2015-01-05 16:40:34
阅读次数:
109
原题链接:https://oj.leetcode.com/problems/two-sum/
撇开暴力破解,这道题有众所周知的两种做法:
1. 先排序,再一前一尾双指针。这种方法要注意的是,排序时需要保存原来的index,这样的话其实是一个有着value和index的结构体基于value的排序。
2. 直接hash。这道题需要注意的是,如果数组有两个相同元素,但是仍然构成唯一解。比如...
分类:
其他好文 时间:
2015-01-05 14:54:31
阅读次数:
190
#include
using namespace std;
int gcd(int m, int n)
{
int temp = 0;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
while (0 != m%n)
{
temp = n;
...
分类:
其他好文 时间:
2015-01-05 11:11:57
阅读次数:
128
https://oj.leetcode.com/problems/merge-sorted-array/http://blog.csdn.net/linhuanmars/article/details/19712333publicclassSolution{
publicvoidmerge(intA[],intm,intB[],intn){
//SolutionA:
//merge_NoExtraSpace(A,m,B,n);
//SolutionB:
merge_ExtraSpace(A,m,B,n);..
分类:
其他好文 时间:
2015-01-05 07:14:31
阅读次数:
141
https://oj.leetcode.com/problems/subsets-ii/http://blog.csdn.net/linhuanmars/article/details/24613193publicclassSolution{
publicList<List<Integer>>subsetsWithDup(int[]num){
Arrays.sort(num);
Set<List<Integer>>results=newHashSet<..
分类:
其他好文 时间:
2015-01-05 07:13:53
阅读次数:
190
https://oj.leetcode.com/problems/largest-rectangle-in-histogram/http://blog.csdn.net/linhuanmars/article/details/20524507publicclassSolution{
publicintlargestRectangleArea(int[]height)
{
//SolutionA
//returnlargestRectangleArea_Expand(height);
//SolutionB
..
分类:
其他好文 时间:
2015-01-05 07:13:52
阅读次数:
132
https://oj.leetcode.com/problems/gray-code/publicclassSolution{
publicList<Integer>grayCode(intn)
{
//规律:
//n=0:
//0
//
//n=1:
//0
//1
//
//n=2:
//00
//01
//11
//10
//
//n=3
//000
//001
//011
//010
//110
//111
//101
//100
//
//设n-1结果集为s
//正序..
分类:
其他好文 时间:
2015-01-05 07:12:52
阅读次数:
150
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled u...
分类:
其他好文 时间:
2015-01-05 07:03:18
阅读次数:
261