Keyboard Row
来源:互联网 发布:电脑必学软件 编辑:程序博客网 时间:2024/05/16 14:36
https://leetcode.com/problems/keyboard-row/?tab=Description
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.
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.
/** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */char** findWords(char** words, int wordsSize, int* returnSize) { static char a[256] = { ['q'] = 1, ['Q'] = 1, ['w'] = 1, ['W'] = 1, ['e'] = 1, ['E'] = 1, ['r'] = 1, ['R'] = 1, ['t'] = 1, ['T'] = 1, ['y'] = 1, ['Y'] = 1, ['u'] = 1, ['U'] = 1, ['i'] = 1, ['I'] = 1, ['o'] = 1, ['O'] = 1, ['p'] = 1, ['P'] = 1, ['a'] = 2, ['A'] = 2, ['s'] = 2, ['S'] = 2, ['d'] = 2, ['D'] = 2, ['f'] = 2, ['F'] = 2, ['g'] = 2, ['G'] = 2, ['h'] = 2, ['H'] = 2, ['j'] = 2, ['J'] = 2, ['k'] = 2, ['K'] = 2, ['l'] = 2, ['L'] = 2, ['z'] = 3, ['Z'] = 3, ['x'] = 3, ['X'] = 3, ['c'] = 3, ['C'] = 3, ['v'] = 3, ['V'] = 3, ['b'] = 3, ['B'] = 3, ['n'] = 3, ['N'] = 3, ['m'] = 3, ['M'] = 3, }; char **res = (char*)malloc(sizeof(char*)*wordsSize); int cur = 0; int j,len; for(int i = 0; i < wordsSize; i++){ len = strlen(words[i]); for(j = 1; j < len; j++) { if(a[words[i][j]] != a[words[i][j-1]]) break; } if(j == len || len == 0) { res[cur] = malloc(len+1); strcpy(res[cur++], words[i]); } } *returnSize = cur; return res;}
0 0
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 500. Keyboard Row
- leetcode-500-Keyboard Row
- 500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- 500. Keyboard Row
- nginx centos7.2安装
- nohup和screen
- loadrunner场景虚拟IP设置
- 天秤男最真实的解析!!
- Android Apk重新打包
- Keyboard Row
- python tab.py
- 关于actionbar中searchview使用
- Oracle层次化查询
- Android应用性能优化之使用SparseArray替代HashMap
- s2-045漏洞分析
- 解决Installation failed with message failed to establish session
- SSM框架——使用MyBatis Generator自动创建代码
- Unity和ios进行相册的一些交互