Find the Difference
来源:互联网 发布:青岛少儿编程培训班 编辑:程序博客网 时间:2024/05/18 05:38
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.思路:注意一点就是:最后return的时候,计算char的index位移,需要转换成char。
public class Solution { public char findTheDifference(String s, String t) { int[] chars = new int[26]; for(int i=0; i<t.length(); i++){ char c = t.charAt(i); chars[c-'a']++; } for(int i=0; i<s.length(); i++){ char c = s.charAt(i); chars[c-'a']--; } for(int i=0; i<chars.length; i++){ if(chars[i] != 0 ){ return (char)('a'+i); } } return t.charAt(0); }}
0 0
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Find the Difference
- 160.Find the Difference
- LeetCode389. Find the Difference
- Find the Difference
- 389. Find the Difference
- Leetcode:Find the Difference
- leetcode_389 Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Find the Difference --LeetCode
- [389]Find the Difference
- 389. Find the Difference
- LeetCode Find the Difference
- Find the Difference
- 第二周项目0-宣告“主权”
- 企业战略管理笔记
- redis3.0.0 集群安装详细步骤
- 阅读Android官方教程 Google Training 1.3 ----- Manage the Activity Lifecycle
- 欢迎使用Markdown编辑器写博客
- Find the Difference
- java的位运算符(>>,<<,>>>,&,|)
- 2016 UESTC Training for Data Structures
- 动态规划练习集(二)
- 理解maven的核心概念
- Master-Slave通用基础框架
- AVPlayer
- 重建二叉树
- google浏览器字体小于12px解决方法