
字符串
stefanharden
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Longest Palindromic Substring 最长回文子串
class Solution { public: string longestPalindrome(string s) { size_t n=s.size(); bool dp[1000][1000]; int startpos=0; int maxlen=1; for(size_t i=0;i原创 2014-01-19 20:30:02 · 441 阅读 · 0 评论 -
Anagrams 打乱字母排列顺序
class Solution { public: vector anagrams(vector &strs) { map> m; vector vec; for(int i=0;i { string tmp=strs[i]; sort(tmp.begin(),tm原创 2014-01-19 22:01:52 · 578 阅读 · 0 评论 -
Integer to Roman 整数转换成罗马数字
class Solution { public: string intToRoman(int num) { string str=""; int value[]={1000,900,500,400,100,90,50,40,10,9,5,4,1}; string symbol[]={"M","CM","D","CD","C","XC","L","XL","X","IX",原创 2014-01-19 21:18:58 · 468 阅读 · 0 评论 -
Valid Number 判断一个数字是否有效
class Solution { public: bool isNumber(const char *s) { if(s==NULL) return false; while(isspace(*s)) s++; if(*s=='+'||*s=='-') s++; bool eAppear=false; bool dotAppear=false;原创 2014-01-19 21:14:45 · 1284 阅读 · 0 评论 -
Valid Palindrome 判断一个字符串是否是回文串
class Solution { public: bool isValidchar(char c) { if(c>='a'&&c if(c>='A'&&c if(c>='0'&&c else return false; } char lowercase(char c)原创 2014-01-19 20:04:18 · 498 阅读 · 0 评论 -
Count and Say 数和说
class Solution { public: string revolution(string s) { string ret=""; char pre=s[0]; int count=1; for(int i=1;i { if(s[i]==pre)原创 2014-01-19 21:38:29 · 404 阅读 · 0 评论 -
Roman to Integer 罗马数字转换成整数
class Solution { public: int table(char c) { switch(c) { case'I':return 1; case'V':return 5; case'X':re原创 2014-01-19 21:34:31 · 473 阅读 · 0 评论 -
Longest Common Prefix 最长公共前缀
class Solution { public: string longestCommonPrefix(vector &strs) { int n=strs.size(); if(n==0) return""; int length=INT_MAX; string result=""; for(int i=0;i { if(strs[i].size()原创 2014-01-19 20:53:23 · 398 阅读 · 0 评论 -
Regular Expression Matching 正则表达式匹配
class Solution { public: bool isMatch(const char *s, const char *p) { if(*p=='\0') return *s=='\0'; if(*(p+1)!='*') { if(*s==*p||*p=='.'&&*s!='\0')原创 2014-01-19 20:36:37 · 591 阅读 · 0 评论 -
Add Binary 二进制相加
class Solution { public: string addBinary(string a, string b) { size_t n=a.size()>b.size()?a.size():b.size(); int carry=0; string result; reverse(a.begin(原创 2014-01-19 20:16:32 · 514 阅读 · 0 评论 -
String to Integer (atoi) 将字符串转化成整数
class Solution { public: int atoi(const char *str) { if(str==NULL) return 0; int sign=1; long long result=0; while(*str==' ') str++; if(*str==原创 2014-01-19 20:13:26 · 385 阅读 · 0 评论 -
Length of Last Word 最后一个单词的长度
public: int lengthOfLastWord(const char *s) { int n=strlen(s)-1; while(s[n]&&s[n]==' ') n--; int len=0; while(s[n]!=' '&&s[n]) { len++; n--; } return len; } };原创 2014-01-19 22:07:13 · 477 阅读 · 0 评论 -
Simplify Path 绝对路径的简单化
class Solution { public: string simplifyPath(string path) { stack s; string tmp; for(int i=0;i { if(path[i]=='/') {原创 2014-01-19 22:04:11 · 419 阅读 · 0 评论 -
Wildcard Matching 通配符匹配
class Solution { public: bool isMatch(const char *s, const char *p) { if(*p=='\0') return *s=='\0'; if(*p=='*') { while(*p=='*') p++;原创 2014-01-19 20:46:34 · 475 阅读 · 0 评论 -
Implement strStr() 字符串匹配(KMP)
class Solution { public: void generate_kmp_next(char *needle,vector &next) { int needlen=strlen(needle); if(needlen==0) return; next.resize(needlen);原创 2014-01-19 20:08:32 · 508 阅读 · 0 评论