-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaytm2.java
More file actions
139 lines (102 loc) · 2.15 KB
/
Copy pathPaytm2.java
File metadata and controls
139 lines (102 loc) · 2.15 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
public class Paytm2 {
/**
MyStack : FILO
push()-->O(1)
pop()-->O(1)
isEmpty()
MyQueue : FIFO
enqueue()-->O(1)
dequeue()-->O(1)
isEmpty()
enqueue(1)
enqueue(2)
enqueue(3)
dequeue() -> return 1
enqueue(4)
dequeue() -> return 2
enqueue(5)
dequeue() -> return 3
dequeue() -> return 4
dequeue() -> return 5
s1 -> []
s2 -> [5,4]
1,2,3
class MyQueue {
MyStack s1 = new MyStack();
MyStack s2 = new MyStack();
public void enqueue(int element) {
s1.push(element);
}
public int dequeue() {
if(this.isEmpty()) return -1;
if(s2.isEmpty()) {
while(!s1.isEmpty()) {
s2.push(s1.pop());
}
return s2.pop();
} else {
return s2.pop();
}
}
public boolean isEmpty() {
return (s1.isEmpty() && s2.isEmpty())
}
}
final class MySingleton {
private static MySingleton instance;
private MySingleton() {}
public static MySingleton getInstance() {
if(instance != null) return instance;
synchronized {
if(instance == null) {
instance = new MySingleton();
}
return instance;
}
}
}
class TestClass {
public static void main(String [] args) {
MySingleton singletonOne = MySingleton.getInstance();
MySingleton singletonTwo = MySingleton.getInstance();
}
}
class Node {
int value;
Node next;
}
L1: 5->6->7
L2: 1->0->8->3
———————
L3: 1->6->5->0
Node findSumOfLinkedLists(Node L1, Node L2){
int n1 = findInteger(L1);
int n2 = findInteger(L2);
int result = n1 + n2;
}
Node convertToList(int n) {
//1650 -
Node nextNode = new Node();
Node temp;
while(n != 0) {
int rem= n%10;
temp = new Node(rem);
temp.next = nextNode.next;
nextNode.next = temp;
n = n/10;
}
// [1]
// nextNode ->[1]-> [6]-> [5] -> [0] -> null
//nextNode -> [0]->null
return nextNode.next;
}
int findInteger(Node node) {
int sum = 0;
while(node != null) {
sum = (sum*10)+node.value;
node = node.next;
}
return sum;
}
*/
}