389. Find the Difference
来源:互联网 发布:网络贷款公司合法的吗 编辑:程序博客网 时间:2024/06/05 18:44
389. Find the Difference
DescriptionHintsSubmissionsDiscussSolution
DiscussPick One
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.
题意:
找出两个字符串中不同的那个字母
算法思路:
因为两个字符串只差一个字母,所以可以把两个字符串的每个字符求和之后相减,然后就可以得到多出的那一个
代码实现:
package easy;public class FindtheDifference {public static char findTheDifference(String s, String t) {int temp=0; for(int i=0; i<t.length(); i++){ temp += t.charAt(i); } for(int i=0; i<s.length(); i++){ temp -= s.charAt(i); } char result = (char)temp; return result; }public static void main(String[] args) {char re = findTheDifference("abcd", "abcde");System.out.println(re);}}
阅读全文
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
- 字符编码杂谈
- HDU 2035 快速幂
- oracle pl/sql Nested Table
- Quartz 事务管理
- 51Nod 1080 两个数的平方和
- 389. Find the Difference
- jquery 表单 清空
- HDU
- oracle8i 9i 10g中ig的意思
- C/C++动态内存管理
- Linux设备驱动remap_pfn_range() 和remap_page_range()
- 查询表相关的存储对象
- IOTA-663A,B Liquid Silicone rubber foam
- js中let、var、const定义变量的区别