zoukankan      html  css  js  c++  java
  • leetcode刷题笔记389题 找不同

    leetcode刷题笔记389题 找不同

    地址:389. 找不同

    问题描述:

    给定两个字符串 s 和 t,它们只包含小写字母。

    字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。

    请找出在 t 中被添加的字母。

    示例 1:

    输入:s = "abcd", t = "abcde"
    输出:"e"
    解释:'e' 是那个被添加的字母。
    示例 2:

    输入:s = "", t = "y"
    输出:"y"
    示例 3:

    输入:s = "a", t = "aa"
    输出:"a"
    示例 4:

    输入:s = "ae", t = "aea"
    输出:"a"

    提示:

    0 <= s.length <= 1000
    t.length == s.length + 1
    s 和 t 只包含小写字母

    //使用异或处理仅有一个不同的问题
    object Solution {
        def findTheDifference(s: String, t: String): Char = {
            var ret = 0
            for (x <- s) {
                ret ^= x
            }
            for(x <- t) {
                ret ^= x
            }
    
            return ret.toChar
        }
    }
    
    func findTheDifference(s string, t string) byte {
        ret := 0
        for _, x := range s {
            ret ^= int(x)
        }
        for _, y := range t {
            ret ^= int(y)
        }
    
        return byte(ret)
    }
    
  • 相关阅读:
    MySQL 5.5版本数据库介绍与二进制安装
    nginx配置文件的基础优化
    yum源是什么
    微服务之间调用token管理
    微服务之间调用事务处理
    idea
    sentry
    infinispan配置
    微服务事务处理
    高并发处理
  • 原文地址:https://www.cnblogs.com/ganshuoos/p/14155095.html
Copyright © 2011-2022 走看看