FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/java/389_Find_the_Difference.java at master · jakehoare/leetcode · GitHub
jakehoare
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
30
Star
51
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
java
/
389_Find_the_Difference.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (19 loc) · 686 Bytes
Breadcrumbs
leetcode
/
java
/
389_Find_the_Difference.java
Copy path
File metadata and controls
23 lines (19 loc) · 686 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
https://leetcode.com/problems/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.
Find the sum of the ASCII values of all chars in t and subtract the sum from s.
Time - O(n)
Space - O(1)
*/
public
class
Solution
{
public
char
findTheDifference
(
String
s
,
String
t
) {
int
charSum
= (
int
)
t
.
charAt
(
t
.
length
() -
1
);
for
(
int
i
=
0
;
i
<
s
.
length
(); ++
i
) {
charSum
+= (
int
)
t
.
charAt
(
i
);
charSum
-= (
int
)
s
.
charAt
(
i
);
}
return
(
char
)
charSum
;
}
}
Back
|
FazBrowse Home
|
New Git URL