【第22期】观点:IT 行业加班,到底有没有价值?

LeetCode—389. Find the Difference

原创 2016年08月29日 10:01:48

Find the Difference思路:建立一个长度26的数组,循环字符串s和t即可。


GitHub地址https://github.com/corpsepiges/leetcode

点此进入如果可以的话,请点一下star,谢谢。



public class Solution {
    public char findTheDifference(String s, String t) {
        int length=s.length();
        char[] cs=s.toCharArray();
        char[] ct=t.toCharArray();
        int[] nums=new int[26];
        nums[ct[length]-'a']++;
        for (int i = 0; i < length; i++) {
            nums[cs[i]-'a']--;
            nums[ct[i]-'a']++;
        }
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]!=0) {
                return (char) ('a'+i);
            }
        }
        return 0;
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

【python】【leetcode】【算法题目389—Find the Difference】

题目原文: Given two strings s and t which consist of only lowercase letters. String t is generated by ra...

Difference between matches() and find() in Java Regex Matcher

I am trying to understand the difference between <a
  • jusi
  • jusi
  • 2014-12-11 14:21
  • 97

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

[LeetCode]153.Find Minimum in Rotated Sorted Array

【题目】 Suppose a sorted array is rotated at some pivot unknown to you beforehan

LeetCode 389. Find the Difference

题目: Given two strings s and t which consist of only lowercase letters. String t is generated by ra...

[LeetCode]162.Find Peak Element

【题目】 A peak element is an element that is greater than its neighbors. <p
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)