389. Find the Difference
来源:互联网 发布:淘宝cvr 编辑:程序博客网 时间:2024/05/01 21:31
Difficulty: Easy
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.
c语言
//#include <string.h>char findTheDifference(char* s, char* t) { int count_s[26] = {0}; int count_t[26] = {0}; int i=0; //int ls, lt; //ls = strlen(s); //lt = strlen(t); while(t[i] != '\0') { count_t[t[i] - 'a']++; i++; } i = 0; while(s[i] != '\0') { count_s[s[i]-'a']++; i++; } for(i = 0; i < 26; i++) { if (count_s[i] != count_t[i]) return i+'a'; } return NULL;}
ps:第一遍提交的时候没有把没用到的头文件
0 0
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference*
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Java之Integer内部缓存
- LitePal学习笔记
- python字典与数据库的灵活使用
- 《艺术家眼中的新三峡》之奉节——三峡的变化美的让艺术家落泪
- HashMap(1): 基本存取原理
- 389. Find the Difference
- 延云YDB基于spark进行数据分析的一种新方式
- 利用java.nio.charset.CharsetDecoder自动识别字符集
- Unity插件
- 《艺术家眼中的新三峡》之巫山——新三峡最浪漫的传说
- 爬虫实战代码
- ASP.NET页面乱码问题分析
- 全国政协委员:打好新三峡文化旅游“两张牌”
- 127.0.0.1