17.Letter Combinations of a Phone Number (char* 和 string 相互转化)
leetcode 第17题 分析 char*和string相互转化
default (1) string();
copy (2) string (const string& str);
substring (3) string (const string& str, size_t pos, size_t len = npos);
from c-string (4) string (const char* s);
from buffer (5) string (const char* s, size_t n);
fill (6) string (size_t n, char c);
range (7) template <class InputIterator> //vector<string> v;
//str(v.begin(),v.end());
string (InputIterator first, InputIterator last);
initializer list (8) string (initializer_list<char> il);
move (9) string (string&& str) noexcept;
#include <iostream>
#include <vector>
#include <string> using namespace std; class Solution { public:
vector<string> letterCombinations(string digits) {
vector< vector<char> >phone{{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
if(digits.empty()) return vector<string>{}; vector<string> resNext=letterCombinations(digits.substr()); int curNum=digits[]-''-;
vector<char> vc(phone[curNum]);
vector<string> resCur; for(auto &each:vc){
vector<string> temp(resNext);
//这一行不能丢,temp为空的时候 char->string if(temp.empty()){string s(&each,);resCur.push_back(s);continue;}
for(auto& str:temp){
str=each+str;
}
resCur.insert(resCur.end(),temp.begin(),temp.end());
}
return resCur;
}
}; int main(){
Solution sol;
string digits="";
vector<string> res=sol.letterCombinations(digits);
for(int i=;i<res.size();++i){
cout<<res[i]<<endl;
}
}
17.Letter Combinations of a Phone Number (char* 和 string 相互转化)的更多相关文章
- Leetcode 17. Letter Combinations of a Phone Number(水)
17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive ...
- 刷题17. Letter Combinations of a Phone Number
一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
- Leetcode 17.——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- 17. Letter Combinations of a Phone Number(bfs)
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- 17. Letter Combinations of a Phone Number (backtracking)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
随机推荐
- P4781 拉格朗日插值
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #def ...
- 数据结构实验之栈与队列四:括号匹配(SDUT 2134)
#include <bits/stdc++.h> using namespace std; typedef long long ll; char s[100]; char a[100]; ...
- 内存管理2-set方法的内存管理
1.对象之间的内存管理: 每个学生都有一本书 book类 @price 学生类 @age @book -------------------- #import "book.h" ...
- c语言 指针数组
指针数组指针数组是数组,指针数组每个元素是一个指针指针数组的定义:type* parray[n]; type* 是数组中每个元素的类型parray 为数组名n为大小 例子:float* a[3] // ...
- Spring框架IOC解说
控制反转——Spring通过一种称作控制反转(IoC)的技术促进了松耦合.当应用了IoC,一个对象依赖的其它对象会通过被动的方式传递进来,而不是这个对象自己创建或者查找依赖对象.你可以认为IoC与JN ...
- Java实现单例的5种方式
1. 什么是单例模式 单例模式指的是在应用整个生命周期内只能存在一个实例.单例模式是一种被广泛使用的设计模式.他有很多好处,能够避免实例对象的重复创建,减少创建实例的系统开销,节省内存. 2. 单例模 ...
- leetcode 560. Subarray Sum Equals K 、523. Continuous Subarray Sum、 325.Maximum Size Subarray Sum Equals k(lintcode 911)
整体上3个题都是求subarray,都是同一个思想,通过累加,然后判断和目标k值之间的关系,然后查看之前子数组的累加和. map的存储:560题是存储的当前的累加和与个数 561题是存储的当前累加和的 ...
- C++ STL Heap算法
#include <iostream>#include <algorithm>#include <vector> using namespace std; int ...
- 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_22-CMS前端页面查询开发-Api调用-跨域解决
点击页面查询按钮 ,报错.跨域问题. 前端端口是11000 请求后端的服务地址端口是31001 出现跨域 开始解决跨域 把前面带端口的地址 用变量代替 只有带/api/cms开头的就转发的服务端310 ...
- 怎么理解linux的平均负载及平均负载高后的排查工具
什么是平均负载 平均负载可以对于我们来说及熟悉又陌生,但我们问平均负载是什么,但大部分人都回答说平均负载不就是单位时间内CPU使用率吗?其实并不是这样的,如果可以的话,可以 man uptime 来了 ...