389. Find the Difference
来源:互联网 发布:手机指纹解锁软件 编辑:程序博客网 时间:2024/06/06 03:00
原题
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:eExplanation:'e' is the letter that was added.
代码实现
public char FindTheDifference(string s, string t) { int[] hash = new int[123]; //97~122 foreach (var ch in s) hash[Convert.ToInt32(ch)]++; foreach (var ch in t) { int tmp = Convert.ToInt32(ch); hash[tmp]--; if (hash[tmp] < 0) return ch; } return ' '; }
leetcode-solution库
leetcode算法题目解决方案每天更新在github库中,欢迎感兴趣的朋友加入进来,也欢迎star,或pull request。https://github.com/jackzhenguo/leetcode-csharp
2 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
- Hibernate4调用SQL和存储过程
- C++多线程
- Codeforces 670D2 Magic Powder
- Log4Net使用详解
- js数组与对象的区别
- 389. Find the Difference
- Vuex,从入门到放弃
- jdk环境配置
- Visual Studio Code 1.11 发布
- IntelliJ IDEA使用Maven创建Java Web项目
- .net aspx ashx sharepoint 输出图片IE不显示
- 557. Reverse Words in a String III
- adb shell input text 完美支持中文输入
- 水平垂直居中图片及文字(兼容IE6+)