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)
    }
    
  • 相关阅读:
    ASCII,Unicode,UTF
    C#值类型和引用类型2
    C#中使用Foreach
    CSS基础(2)
    CSS基础
    HTML基础
    MySQL高级
    MySQL和Python交互案例练习(2)
    MySQL和Python交互案例练习(1)
    外键SQL语句的编写
  • 原文地址:https://www.cnblogs.com/ganshuoos/p/14155095.html
Copyright © 2011-2022 走看看