-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet.java
More file actions
58 lines (40 loc) · 1012 Bytes
/
leet.java
File metadata and controls
58 lines (40 loc) · 1012 Bytes
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
import java.util.LinkedList;
public class leet {
public static void main(String[] args) {
LinkedList <Integer> l1= new LinkedList<>();
l1.add(3);
l1.add(2);
l1.add(1);
LinkedList <Integer> l2= new LinkedList<>();
l2.add(6);
l2.add(5);
l2.add(7);
int sum=0;
int temp=0;
for(int x : l1){
temp=(temp)*10+x;
}
System.out.println(temp);
int val1=reverse(temp);
int temp1=0;
for(int x : l2){
temp1=(temp1)*10+x;
}
System.out.println(temp1);
int val2=reverse(temp1);
sum=val1+val2;
System.out.println(sum);
System.out.println(reverse(sum));
}
public static int reverse(int temp){
int val=0;
int a=0;
while (temp!=0){
a=temp%10;
val=(val*10)+a;
temp=temp/10;
}
System.out.println(val);
return val;
}
}