Ch1-4: anagram string
来源:互联网 发布:ubuntu切换中文 编辑:程序博客网 时间:2024/05/16 07:18
1. The simplest method is to sort these strings (O(nlogn)) and then compare them(O(n)).
bool isAnagram1(string s, string t){ // why cannot use &? if(s=="" || t=="") return false; if(s.length() != t.length()) return false; sort(&s[0], &s[0]+s.length());// why must use &(reference)? sort(&t[0], &t[0]+t.length()); if(s == t) return true; else return false;}
2. Use scoreboard to note the times each ASCII shows, when find one in s1, add it, then if find it in s2 too, minus it, to see if the scoreboard is == 0;
Compiling the source code....
$g++ -std=c++11 main.cpp -o demo -lm -pthread -lgmpxx -lgmp -lreadline 2>&1
$g++ -std=c++11 main.cpp -o demo -lm -pthread -lgmpxx -lgmp -lreadline 2>&1
Executing the program....
$democ[99]=1c[100]=-11
0 0
- Ch1-4: anagram string
- string permutation, anagram
- String ---Valid Anagram
- anagram
- Anagram
- Anagram
- Anagram
- CH1-3: remove duplicate char in a string, with/without additional buffer
- Ch1-5: Write a method to replace all spaces in a string with ‘%20’.
- 精粹ch1
- Ch1:概述
- Ch1:概述
- ch1 基础知识
- ch1 开始
- 读书笔记之:Linux程序设计(第4版)(ch1-7) [ 学如逆水行舟,不进则退 ]
- 读书笔记之:Linux程序设计(第4版)(ch1-7) [ 学如逆水行舟,不进则退
- [Linux] 读书笔记之:Linux程序设计(第4版)(ch1-7) [ 学如逆水行舟,不进则退 ]
- corejsf note ch1
- python for android : 广州公交实时查询
- hdu_1211 RSA (扩展欧几里得)
- 重装ORACLE10G体悟
- u盾三个房间看电视恢复健康萨丹哈看
- 沙盒路径 和 项目包路径
- Ch1-4: anagram string
- IOS开发相关网站大集合分享
- 如何防止从google.com跳转google.com.hk
- C/C++注册常量或函数到Lu系统
- Geeks面试题: Egg Dropping Puzzle
- 关于cookie
- 网络公关删帖多少钱一贴啊,我想找人删帖,不知道行情啊!
- 汇编程序开发环境搭配(转载)
- 如何进行软件需求分析