Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 599033c

Browse files
leetcode: add 641
1 parent fdccbe0 commit 599033c

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class MyCircularDeque {
12+
public:
13+
list<int> v;
14+
int count;
15+
MyCircularDeque(int k) {
16+
v.clear();
17+
count=k;
18+
}
19+
20+
bool insertFront(int value) {
21+
if(v.size()!=count){
22+
v.push_front(value);
23+
return true;
24+
}
25+
else{
26+
return false;
27+
}
28+
}
29+
30+
bool insertLast(int value) {
31+
if (v.size() != count)
32+
{
33+
v.push_back(value);
34+
return true;
35+
}
36+
else
37+
{
38+
return false;
39+
}
40+
}
41+
42+
bool deleteFront() {
43+
if (v.size() != 0)
44+
{
45+
v.pop_front();
46+
return true;
47+
}
48+
else
49+
{
50+
return false;
51+
}
52+
}
53+
54+
bool deleteLast() {
55+
if (v.size() != 0)
56+
{
57+
v.pop_back();
58+
return true;
59+
}
60+
else
61+
{
62+
return false;
63+
}
64+
}
65+
66+
int getFront() {
67+
if (v.size() != 0)
68+
{
69+
return v.front();
70+
}
71+
else
72+
{
73+
return -1;
74+
}
75+
}
76+
77+
int getRear() {
78+
if (v.size() != 0)
79+
{
80+
return v.back();
81+
}
82+
else
83+
{
84+
return -1;
85+
}
86+
}
87+
88+
bool isEmpty() {
89+
if(v.size()==0){
90+
return true;
91+
}
92+
else{
93+
return false;
94+
}
95+
}
96+
97+
bool isFull() {
98+
if (v.size() == count)
99+
{
100+
return true;
101+
}
102+
else
103+
{
104+
return false;
105+
}
106+
}
107+
};
108+
109+
/**
110+
* Your MyCircularDeque object will be instantiated and called as such:
111+
* MyCircularDeque* obj = new MyCircularDeque(k);
112+
* bool param_1 = obj->insertFront(value);
113+
* bool param_2 = obj->insertLast(value);
114+
* bool param_3 = obj->deleteFront();
115+
* bool param_4 = obj->deleteLast();
116+
* int param_5 = obj->getFront();
117+
* int param_6 = obj->getRear();
118+
* bool param_7 = obj->isEmpty();
119+
* bool param_8 = obj->isFull();
120+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /