Leetcode 389. Find the Difference [Java] | GOOGLE coding interview question
ฝัง
- เผยแพร่เมื่อ 22 ส.ค. 2024
- Check out how to solve the leetcode 389 Find the Difference question in Java. This is one of GOOGLE's most commonly asked coding interview questions according to Leetcode.
Question URL: leetcode.com/p...
Please write in the comments below which leetcode problem you want me to solve next.
And remember, a leetcode a day keeps unemployment away!
Thanks for watching!
#leetcode389
A problem with this solution is there could be a possible integer overflow (very large strings). To overcome this, you can add a character at index “i” in “t” and immediately subtract character at index “i” in “s”.
When loop ends, you will be left with one character in “t”. Add it to your result.
Yep, you are absolutely correct. This solution was based just on the constrains that leetcode provided (P.S. 0
class Solution {
public char findTheDifference(String s, String t) {
int sC = 0;
int tC = 0;
for(int i=0; i