leetcode-2-basic
解题思路:
题目本身挺简单的,考虑用set,判断每个单词的字母是不是属于同一个集合。需要注意的是:1)set的构造方法;2)单词可能是大小写混合的,不一定只是首字母大写;
3)break是跳出循环=。=switch写的时候要注意,不好用的话还是用if-else好了。
vector<string> findWords(vector<string>& words) {
char f[20] = {'q','w','e','r','t','y','u','i','o','p','Q','W','E','R','T','Y','U','I','O','P'};
set<char>first(f,f+20);
char s[18] = {'a','s','d','f','g','h','j','k','l','A','S','D','F','G','H','J','K','L'};
set<char>second(s, s+18);
char t[14] = {'z','x','c','v','b','n','m','Z','X','C','V','B','N','M'};
set<char>third(t, t+14);
vector<string>::iterator it;
string temp = "";
vector<string> result;
bool flag = true;
int i;
for (it = words.begin(); it != words.end(); it++) { temp = *it;
flag = true; if (temp.length() == 1) {
result.insert(result.end(), temp);
continue;
}
if (first.find(temp[0]) != first.end()) {
for (i = 1; i < temp.length(); i++) {
if (first.find(temp[i]) == first.end()) {
break;
}
}
if (i != temp.length()) {
flag = false;
continue;
}
}
else if (second.find(temp[0]) != second.end()) {
for (i = 1; i < temp.length(); i++) {
if (second.find(temp[i]) == second.end()) {
break;
}
}
if (i != temp.length()) {
flag = false;
continue;
}
}
else {
for (i = 1; i < temp.length(); i++) {
if (third.find(temp[i]) == third.end()) {
break;
}
}
if (i != temp.length()) {
flag = false;
continue;
}
} if (flag == true) {
result.insert(result.end(), temp);
}
}
return result;
}
leetcode-2-basic的更多相关文章
- [LeetCode] 224. Basic Calculator 基本计算器
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- [LeetCode] 227. Basic Calculator II 基本计算器 II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- [LeetCode] 772. Basic Calculator III 基本计算器之三
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- [LeetCode] 227. Basic Calculator II 基本计算器之二
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- LeetCode#227.Basic Calculator II
题目 Implement a basic calculator to evaluate a simple expression string. The expression string contai ...
- Java for LeetCode 227 Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- Java for LeetCode 224 Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- (medium)LeetCode 224.Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- (medium)LeetCode 227.Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- leetcode 224. Basic Calculator 、227. Basic Calculator II
这种题都要设置一个符号位的变量 224. Basic Calculator 设置数值和符号两个变量,遇到左括号将数值和符号加进栈中 class Solution { public: int calcu ...
随机推荐
- ZOJ3329(数学推导+期望递推)
要点: 1.期望的套路,要求n以上的期望,则设dp[i]为i分距离终点的期望步数,则终点dp值为0,答案是dp[0]. 2.此题主要在于数学推导,一方面是要写出dp[i] = 什么,虽然一大串但是思维 ...
- js onclick=‘save()’ 和 onclick='return save()'
onclick="function()" 表示只会执行 function , 但是不会传回 function 中之回传值onclick = "return functio ...
- CSS入门使用
声明标签 HTML <!DOCTYPE> 内链样式表 <body style="background-color:green;margin:0;padding:0;&quo ...
- Azkaban是什么?(一)
不多说,直接上干货! http://www.cnblogs.com/zlslch/category/938837.html Azkaban是什么? Azkaban是一套简单的任务调度服务,整体包括三 ...
- javaoo面向对象
- split命令:文件切割
split命令:文件切割 有时候文件过大,导致不能正常使用,可以用split进行切割. 命令参数: split [选项] [要切割的文件] [输出文件名前缀] -a, --suffix-length= ...
- nodejs 不是单线程
nodejs 不是单线程 在我机器上,nodejs 起了近 20 个线程. 对,你没有看错,20个线程.
- c# 实现窗体移动
一般情况下: .添加下列代码到你的窗体中: #region 轻松移动 bool isInMove; Point oldPoint; void InitializeEasyMove() { isInMo ...
- Gin框架body参数获取
需求: 记录所有请求的json数据 body, _ := ioutil.ReadAll(c.Request.Body) if body != nil { log.Info("请求body内容 ...
- React项目搭建(脚手架)
首先我们需要安装node环境:download nodejs:https://i.cnblogs.com/EditPosts.aspx?opt=1 找到你需要的版本和系统安装包下载并安装. 这时候你可 ...