389. Find the Difference
2017-03-12 14:39
225 查看
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语言
ps:第一遍提交的时候没有把没用到的头文件
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:第一遍提交的时候没有把没用到的头文件
相关文章推荐
- leetcode - 389. Find the Difference
- [leetcode: Python]389. Find the Difference
- 【LeetCode】 389. Find the Difference
- [LeetCode]389. Find the Difference
- 【LeetCode】389. Find the Difference
- 389. Find the Difference
- [LeetCode]--389. Find the Difference
- 389. Find the Difference的C++解法
- LeetCode - 389. Find the Difference - 三种不同解法 - ( C++ ) - 解题报告
- 389.Find the Difference
- LeetCode 389. Find the Difference
- LeetCode - 389 - Find the Difference
- 389. Find the Difference
- LeetCode 389 Find the Difference
- leetcode_389 Find the Difference
- 389. Find the Difference
- 389. Find the Difference注意异或运算的巧妙使用^
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference