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] 277. Find the CelebrityLeetCode
- LeetCode之Find Common Characters(Kotlin)LeetCodeKotlin
- [LeetCode] 724. Find Pivot IndexLeetCodeIndex
- [LeetCode] 2028. Find Missing ObservationsLeetCode
- [leetcode] 890. Find and Replace PatternLeetCode
- [LeetCode] Find First and Last Position of Element in SortedLeetCodeAST
- Leetcode 442. Find All Duplicates in an ArrayLeetCode
- [LeetCode] 2831. Find the Longest Equal SubarrayLeetCode
- [leetcode] 1394. Find Lucky Integer in an ArrayLeetCode
- [LeetCode] 3011. Find if Array Can Be SortedLeetCode
- [LeetCode] 3238. Find the Number of Winning PlayersLeetCode
- LeetCode 438. Find All Anagrams in a StringLeetCode
- 【Leetcode】1673. Find the Most Competitive SubsequenceLeetCode
- [LeetCode] 501. Find Mode in Binary Search TreeLeetCode
- LeetCode | 153. Find Minimum in Rotated Sorted ArrayLeetCode
- LeetCode 448. Find All Numbers Disappeared in an ArrayLeetCodeAPP
- LeetCode 501. Find Mode in Binary Search TreeLeetCode
- Leetcode 34 Find First and Last Position of Element in Sorted ArrayLeetCodeAST
- [LeetCode] 1545. Find Kth Bit in Nth Binary StringLeetCode
- [LeetCode] 1385. Find the Distance Value Between Two ArraysLeetCode
- LeetCode 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance??LeetCode
- What is the difference Put and Post and Get?
- Difference between cursor and a ref cursor
- difference with PerlApp 7.0 and PerlApp 6.0APP
- What is the difference between a Homemaker and a Housewife?
- leetcode 530. Minimum Absolute Difference in BST二叉搜尋樹的最小絕對差 (簡單)LeetCode
- The SQL vs NoSQL Difference: MySQL vs MongoDBMySqlMongoDB
- (轉)leetcode:Find All Anagrams in a String 滑動視窗方法總結LeetCode
- Difference Between Arraylist And Vector : Core Java Interview Collection QuestionJavaView
- 「萌新指南」SOA vs. 微服務:What’s the Difference?微服務
- find命令
- Hello,find!
- Difference between Microsoft Dynamics 365 WEB API, Organization Service and Organization Data ServicROSWebAPI
- Unable to find a specification for ''
- JavaScript find()方法JavaScript
- find -newer命令