会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
xcw0754
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
55
56
57
58
59
60
61
62
下一页
2015年1月9日
C++ vector常用法
摘要: 在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结。 1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<int> vec; (3)尾部插入数字:vec.push_back(a); (4)使用下标访问元素,cout<<vec[0
阅读全文
posted @ 2015-01-09 18:13 xcw0754
阅读(186)
评论(0)
推荐(0)
2015年1月3日
LeetCode ZigZag Conversion(将字符串排成z字型)
摘要: 1 class Solution { 2 public: 3 string convert(string s, int nRows) { 4 string a=""; 5 int len=s.length(); 6 if(lennRows && r...
阅读全文
posted @ 2015-01-03 22:58 xcw0754
阅读(234)
评论(0)
推荐(0)
2014年11月30日
什么是P问题、NP问题和NPC问题
摘要: 转载自:http://www.matrix67.com/blog/archives/105 这或许是众多OIer最大的误区之一。 你会经常看到网上出现“这怎么做,这不是NP问题吗”、“这个只有搜了,这已经被证明是NP问题了”之类的话。你要知道,大多数人此时所说的NP问题其实都是指的NPC问题。他们没
阅读全文
posted @ 2014-11-30 20:33 xcw0754
阅读(146)
评论(0)
推荐(0)
2014年11月27日
LeetCode Reverse Words in a String 将串中的字翻转
摘要: 1 class Solution { 2 public: 3 void reverseWords(string &s) { 4 string end="",tem=""; 5 char *p=&s[0]; 6 whil...
阅读全文
posted @ 2014-11-27 21:52 xcw0754
阅读(167)
评论(0)
推荐(0)
LeetCode Remove Duplicates from Sorted Array II 删除整型数组中的重复元素并返回剩下元素个数2
摘要: 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 int *s=&A[0],*e=&A[0]; //s指向“连续数字”的第一个,e往后遍历相同的 5 int ...
阅读全文
posted @ 2014-11-27 17:03 xcw0754
阅读(234)
评论(0)
推荐(0)
LeetCode Length of Last Word 最后一个字的长度
摘要: 1 class Solution { 2 public: 3 int lengthOfLastWord(const char *s) { 4 if(s=="") return 0; 5 string snew=s; 6 int n=0,...
阅读全文
posted @ 2014-11-27 16:10 xcw0754
阅读(154)
评论(0)
推荐(0)
2014年11月26日
LeetCode Merge Two Sorted Lists 归并排序
摘要: 题意: 将两个有序的链表归并为一个有序的链表。思路: 设合并后的链表为head,现每次要往head中加入一个元素,该元素要么属于L1,要么属于L2,可想而知,此元素只能是L1或者L2的首个元素,那么进行一次比较就可以知道是谁了。操作到L1或L2其中一个已经没有元素为止,剩下的直接加到head后面...
阅读全文
posted @ 2014-11-26 23:16 xcw0754
阅读(169)
评论(0)
推荐(0)
LeetCode Add Binary 两个二进制数相加
摘要: 1 class Solution { 2 public: 3 string addBinary(string a, string b) { 4 if(a==""&&b=="") return ""; 5 if(a=="") return b; 6...
阅读全文
posted @ 2014-11-26 21:50 xcw0754
阅读(475)
评论(0)
推荐(0)
2014年11月24日
LeetCode Climbing Stairs 爬楼梯
摘要: 题意: 一个人在爬楼梯,此楼梯共有n个台阶,每次可以跨1步或者两步。问有多少种方案走完n个台阶?思路: 当n=1时,返回1; 当n=2时,返回2。 当n>3时,要返回的是n-1和n-2所要返回的数之和。比如n=3,那么就返回1+2的值,n=4,返回3+2。类推下去。 其实这是“斐波那契数列...
阅读全文
posted @ 2014-11-24 18:58 xcw0754
阅读(226)
评论(0)
推荐(0)
2014年11月22日
LeetCode Add Two Numbers 两个数相加
摘要: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne...
阅读全文
posted @ 2014-11-22 21:44 xcw0754
阅读(243)
评论(0)
推荐(0)
上一页
1
···
55
56
57
58
59
60
61
62
下一页
公告