LeetCode 389. Find the Difference
Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.
hash表
public char findTheDifference(String s, String t) {
char[] sch = s.toCharArray();
char[] tch = t.toCharArray();
int[] hashs = new int[256];
for(char ch : sch) hashs[ch]++;
for (char ch : tch) {
if(hashs[ch]-- <= 0) return ch;
}
return ' ';
}
相關文章
- [LeetCode] 2903. Find Indices With Index and Value Difference ILeetCodeIndex
- [LeetCode] Find the Duplicate NumberLeetCode
- LeetCode-Find the CelebrityLeetCode
- Find Peak element leetcodeLeetCode
- LeetCode-Find the Duplicate NumberLeetCode
- Leetcode-Find Peak ElementLeetCode
- [LeetCode] 277. Find the CelebrityLeetCode
- [LeetCode] 724. Find Pivot IndexLeetCodeIndex
- [leetcode] 890. Find and Replace PatternLeetCode
- leetcode287: Find the Duplicate NumberLeetCode
- [LeetCode] Find First and Last Position of Element in SortedLeetCodeAST
- Leetcode 442. Find All Duplicates in an ArrayLeetCode
- [leetcode] 1394. Find Lucky Integer in an ArrayLeetCode
- LeetCode-Find K Pairs with Smallest SumsLeetCodeAI
- LeetCode 題解(252) : Find the Duplicate NumberLeetCode
- LeetCode之Find Common Characters(Kotlin)LeetCodeKotlin
- LeetCode 438. Find All Anagrams in a StringLeetCode
- LeetCode-Find Median from Data StreamLeetCode
- Find Minimum in Rotated Sorted Array leetcode javaLeetCodeJava
- Leetcode-Find Minimum in Rotated Sorted ArrayLeetCode
- [LeetCode] 2831. Find the Longest Equal SubarrayLeetCode
- Leetcode 34 Find First and Last Position of Element in Sorted ArrayLeetCodeAST
- LeetCode 448. Find All Numbers Disappeared in an ArrayLeetCodeAPP
- Leetcode-Find Minimum in Rotated Sorted Array IILeetCode
- [LeetCode] 2028. Find Missing ObservationsLeetCode
- [LeetCode] 501. Find Mode in Binary Search TreeLeetCode
- 【Leetcode】1673. Find the Most Competitive SubsequenceLeetCode
- LeetCode | 153. Find Minimum in Rotated Sorted ArrayLeetCode
- LeetCode 501. Find Mode in Binary Search TreeLeetCode
- Leetcode 153. Find Minimum in Rotated Sorted ArrayLeetCode
- [LeetCode] 3011. Find if Array Can Be SortedLeetCode
- What is the difference Put and Post and Get?
- What is the difference between <%, <%=, <%# and -%> in ERB in Rails?AI
- Some difference between mysql & oracleMySqlOracle
- leetCode(Using C)——760. Find Anagram MappingsLeetCodeAPP
- Whats the difference between the v$sql* viewsSQLView
- Difference between business area and profit center
- What is the difference between gross sales and revenue?ROS