补第十一周Leetcode 博客
来源:互联网 发布:js笔试题及答案 编辑:程序博客网 时间:2024/05/16 06:28
补第十一周Leetcode 博客
389.Find the Difference
Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input:
s = “abcd”
t = “abcde”
Output:
e
Explanation:
‘e’ is the letter that was added.
分析
S是初始的字符串,T是将S洗牌后额外加了一个字符的新串,我们统计S中26个小写字母各自出现的次数和T中26个小写字母各自出现的次数,对比两次的统计结果,出现不同的那个对应字母就是额外加的一个。
源代码
class Solution {public: char findTheDifference(string s, string t) { int alphabet[26]; int check[26]; for (int i = 0; i < 26; i++) { alphabet[i] = 0; check[i] = 0; } for (int i = 0; i < s.length(); i++) { alphabet[s[i] - 'a']++; } for (int i = 0; i < t.length(); i++) { check[t[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (alphabet[i] != check[i]) { return i + 'a'; } } return 'a'; }};
运行结果
阅读全文
0 0
- 补第十一周Leetcode 博客
- leetcode-python 第十一周
- leetcode-第十一周
- 第十一周LeetCode
- 第十一周LeetCode
- 第十一周LeetCode
- LeetCode题解 第十一周
- 第十一周阅读程序(补)
- 第十一周LeetCode算法题两道
- 周计划 补完工程 第十一周 matlab练习
- leetcode【第十一周】旋转链表
- 第十一周:[Leetcode]474. Ones and Zeroes
- 第十一周:[Leetcode]139. Word Break
- 第十一周 leetcode 135. Candy(Hard)
- Leetcode 392.Is Subsequence(第十一周作业)
- 第十一周
- 第十一周
- 第十一周
- windows7安装CentOS7及linux的使用2
- macOS high sierra 下搭建redis集群
- Java中long类型为何会自动转换为float类型?(未整理)
- C++虚函数应用
- 网卡类WiFi模块系列三:USB接口双通道单/双频WiFi模块
- 补第十一周Leetcode 博客
- python中在使用asyncio中使用requests
- USB通信协议
- struts2 --- 拦截器
- 中企动力小程序开发服务上市,4大核心功能支持全行业
- 对动态规划DP的深入理解
- Java并发编程规则:判定对象是否存在多线程访问
- 【二进制分组+AC自动机】HDU4787[GRE Words Revenge]题解
- 给c++跪了.cpp