Day 72: force buckle 389, look for different
Address: leetcode-cn.com/problems/fi…
Directions: 1. 2. The map search.
function findTheDifference(s: string, t: string): string { let strs:Array<string> = s.split('').sort(); Let STRT :Array<string> = t.split(").sort(); for(let i:number = 0; i < strs.length; i++) { if(strs[i] ! == strt[i]) { return strt[i]; }} return STRT [strt. length-1]; // If STRS is longer than STRS, the last bit must be different.Copy the code
The map to find:
function findTheDifference(s: string, t: string): string { let strs:Array<string> = s.split('').sort(); let strt:Array<string> = t.split('').sort(); let res:Map<string, number> = new Map(); Let arr: map <string, number> = new map (); for( let i of strs) { res.has(i) ? res.set(i, res.get(i) + 1) : res.set(i, 0); } for(let I of STRT) {arr. Has (I)? arr.set(i, arr.get(i) + 1) : arr.set(i, 0); } for( let i of strt) { if(res.get(i) ! == arr. Get (I)) {return I; }}};Copy the code