TreeviewCopyright © aleen42 all right reserved, powered by aleen42
389. 找不同
https://leetcode-cn.com/problems/find-the-difference/
Java
class Solution {
public char findTheDifference(String s, String t) {
int sum = 0;
for(char c : t.toCharArray()) sum += c;
for(char c : s.toCharArray()) sum -= c;
return (char)sum;
}
}
Python
'''
Author: Goog Tech
Date: 2020-08-24 15:42:44
LastEditTime: 2020-08-24 15:43:35
Description: https://leetcode-cn.com/problems/find-the-difference/
FilePath: \leetcode-googtech\#389. Find the Difference\Solution.py
WebSite: https://algorithm.show/
'''
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
for i in range(len(t)):
if t.count(t[i]) != s.count(t[i]):
return t[i]