-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfind_difference.c
More file actions
64 lines (51 loc) · 1.25 KB
/
find_difference.c
File metadata and controls
64 lines (51 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
auther: Naman Tamrakar
date: 2023-07-19
level: easy
url: https://leetcode.com/problems/find-the-difference/
question: You are given two strings s and t.
String t is generated by random shuffling string s and then add one more letter at a random position.
Return the letter that was added to t.
*/
#include <stdio.h>
#include <stdlib.h>
char findTheDifference_c(char * s, char * t){
int i=0;
int ans=t[i];
while (s[i]!='\0') {
ans += t[i+1] - s[i];
i++;
}
return ans;
}
__attribute__((naked))
char findTheDifference(char * s, char * t){
__asm__(
// int i=0;
"movl $0, %edx;"
// int ans=t[i];
"movb (%rsi,%rdx,1), %al;"
"l1:;"
// while (s[i]!='\0') {
"cmpb $0, (%rdi,%rdx,1);"
"je end;"
// ans -= s[i];
"subb (%rdi,%rdx,1), %al;"
// i++;
"incl %edx;"
// ans += t[i+1] ;
"addb (%rsi,%rdx,1), %al;"
"jmp l1;"
"end:;"
// return ans;
"ret;"
);
}
const int MAX_VAL = 1001;
int main() {
char s[MAX_VAL], t[MAX_VAL];
scanf("%s", s);
scanf("%s", t);
printf("%c\n", findTheDifference(s, t));
return 0;
}