随笔分类 -  字符串处理,C++STL

C++03标准中最强大的工具——标准模板库,提供string,map,vector等各种容器和算法
摘要:找出是否存在nums[i]==nums[j],使得 j - i <=k 这是map的一个应用   阅读全文
posted @ 2016-03-12 12:42 Breeze0806 阅读(129) 评论(0) 推荐(0)
摘要:合并有序数组 时间复杂度O(m+n) 该算法来自各种算法与数据结构书,写得已经烂得不能再烂了,这个应该是最短的代码了吧,不知如何归类 1 class Solution { 2 public: 3 void merge(vector<int>& nums1, int m, vector<int>& n 阅读全文
posted @ 2016-03-10 20:29 Breeze0806 阅读(124) 评论(0) 推荐(0)
摘要:用两个队列去实现栈,这里我使用了队列数组q[2],在所有的过程中保证一个队列是空的 push时插入到空的队列中,然后将队列中的元素移到另一个队列中 pop时从不空的队列中pop() peek时从不空的队列中取出front() 1 class Stack { 2 public: 3 queue<int 阅读全文
posted @ 2016-03-09 21:48 Breeze0806 阅读(168) 评论(0) 推荐(0)
摘要:题意让大数加1 我的做法是先让个位+1,再倒置digits,然后进位,最后倒置digits,得到答案。 1 class Solution { 2 public: 3 vector<int> plusOne(vector<int> &digits) { 4 digits[digits.size() - 阅读全文
posted @ 2016-03-02 21:55 Breeze0806 阅读(139) 评论(0) 推荐(0)
摘要:题目本身是去重 由于我很懒,所以用了STL库里的unique函数来去重,小伙伴们可以考虑自己实现去重的函数,其实并不复杂。 1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 return unique 阅读全文
posted @ 2016-03-02 21:27 Breeze0806 阅读(151) 评论(0) 推荐(0)
摘要:和remove zero类似的方法完成该题 1 class Solution { 2 public: 3 int removeElement(vector<int>& nums, int val) { 4 vector<int>::size_type j = 0; 5 for(vector<int> 阅读全文
posted @ 2016-03-02 21:19 Breeze0806 阅读(123) 评论(0) 推荐(0)
摘要:本题用两个栈实现队列,用栈的基本操作去实现队列的所有基本操作push(),pop(),peek()以及empty() sa作为输入栈,sb作为输出栈,将sa输入元素的反转过来放到sb中 push与sa有关,而pop(),peek()与sb有关,即将sa输入元素出栈放到sb中(函数move). 为此, 阅读全文
posted @ 2016-03-01 19:04 Breeze0806 阅读(175) 评论(0) 推荐(0)
摘要:题意:将罗马数字1到3999转化成自然数字,这里用了STL库map将罗马字符映射到自然数字。I,V,X,L,C,D,M -> 1,5,10,50,100,500,1000m[s[i]] m; 4 Solution(){ 5 const int N = 7; 6 ... 阅读全文
posted @ 2016-01-25 22:17 Breeze0806 阅读(168) 评论(0) 推荐(0)
摘要:先介绍下本题的题意:在一个字符串组成的数组words中,找出max{Length(words[i]) * Length(words[j])},其中words[i]和words[j]中没有相同的字母,在这里字符串由小写字母a-z组成的。对于这道题目我们统计下words[i]的小写字母a-z是否存在,然... 阅读全文
posted @ 2016-01-24 20:49 Breeze0806 阅读(383) 评论(0) 推荐(1)
摘要:字符串s和字符串t是否异构,就是统计两个字符串的a-z的字符数量是否一值 1 class Solution { 2 public: 3 4 bool isAnagram(string s, string t) { 5 int flgs[26] = {0};//统计s a-z... 阅读全文
posted @ 2016-01-17 21:57 Breeze0806 阅读(176) 评论(0) 推荐(0)
摘要:找出数组中重复的数,裸的map和set题 1 class Solution { 2 public: 3 bool containsDuplicate(vector<int>& nums) { 4 map<int,int> mii; 5 for (int i = 0;i<nums.size() ;++ 阅读全文
posted @ 2016-01-16 20:23 Breeze0806 阅读(148) 评论(0) 推荐(0)
摘要:本质是把26进制转化为10进制 A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 1 class Solution { 2 public: 3 int titleToNumber(string s... 阅读全文
posted @ 2016-01-16 20:13 Breeze0806 阅读(155) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public: 3 void moveZeroes(vector& nums) { 4 int j = 0; 5 for(int i = 0; i< nums.size(); ++i){ 6 ... 阅读全文
posted @ 2016-01-15 11:58 Breeze0806 阅读(210) 评论(2) 推荐(1)