国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

500. Keyboard Row

2019-11-11 02:41:43
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Given a List of Words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.

American keyboard

Example 1:

Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]

Note:

You may use one character in the keyboard more than once.You may assume the input string will only contain letters of alphabet.

Subscribe to see which companies asked this question.

判斷一個(gè)單詞的字母是否都在鍵盤(pán)的同一行。

代碼:

class Solution{public:	vector<string> findWords(vector<string>& words) 	{		s = "QWERTYUIOP";		make_map(1);		s = "ASDFGHJKL";		make_map(2);		s = "ZXCVBNM";		make_map(3);		vector<string>res;		for(auto word:words)		{			int n = 0;			for(auto c:word)			{				int k = toupper(c) - 'A';				if(n != 0 && n != map[k]) 				{					n = 4;					break;				}				n = map[k];			}			if(n < 4) res.push_back(word);		}		return res;	}PRivate:	int map[26];	string s;	void make_map(int n)	{		for(auto c:s)		{			map[c-'A'] = n;		}	}};


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 孟村| 承德市| 泗阳县| 普安县| 大厂| 大庆市| 兴安盟| 宁明县| 德钦县| 当涂县| 革吉县| 二连浩特市| 凤凰县| 桂阳县| 肥城市| 揭阳市| 平陆县| 美姑县| 宜都市| 任丘市| 宜春市| 甘德县| 乌兰察布市| 大姚县| 枞阳县| 中方县| 孟津县| 天峻县| 宁强县| 普定县| 泸州市| 蓝田县| 礼泉县| 普格县| 城市| 平舆县| 尼玛县| 平谷区| 镇坪县| 辽阳市| 屯留县|