Movatterモバイル変換


[0]ホーム

URL:


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

Commit31064d5

Browse files
add 622
1 parente8a6150 commit31064d5

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ _If you like this project, please leave me a star._ ★
591591
|625|[Minimum Factorization](https://leetcode.com/problems/minimum-factorization/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_625.java)||Medium|
592592
|624|[Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_624.java) | |Easy | Sort, Array
593593
|623|[Add One Row to Tree](https://leetcode.com/problems/add-one-row-to-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_623.java) | |Medium | Tree
594+
|622|[Design Circular Queue](https://leetcode.com/problems/design-circular-queue/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_622.java) | |Medium | Design, Queue
594595
|621|[Task Scheduler](https://leetcode.com/problems/task-scheduler/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_621.java) | |Medium | Greedy, Queue
595596
|617|[Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_617.java) | |Easy | Tree, Recursion
596597
|616|[Add Bold Tag in String](https://leetcode.com/problems/add-bold-tag-in-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_616.java) | | Medium | String
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_622 {
6+
publicstaticclassSolution1 {
7+
publicstaticclassMyCircularQueue {
8+
9+
int[]arr;
10+
intrearIndex;//this one points to the rear of the queue and could grow to 3000 which is the max calls that this problem is bound to
11+
intsize;//this is the max size of this circule queue
12+
intfrontIndex;
13+
14+
publicMyCircularQueue(intk) {
15+
arr =newint[k];
16+
Arrays.fill(arr, -1);
17+
size =k;
18+
rearIndex =0;
19+
frontIndex =0;
20+
}
21+
22+
publicbooleanenQueue(intvalue) {
23+
if (arr[rearIndex %size] == -1) {
24+
arr[rearIndex %size] =value;
25+
rearIndex++;
26+
returntrue;
27+
}else {
28+
returnfalse;
29+
}
30+
}
31+
32+
publicbooleandeQueue() {
33+
if (arr[frontIndex %size] != -1) {
34+
arr[frontIndex %size] = -1;
35+
frontIndex++;
36+
returntrue;
37+
}else {
38+
returnfalse;
39+
}
40+
}
41+
42+
publicintFront() {
43+
returnarr[frontIndex %size];
44+
}
45+
46+
publicintRear() {
47+
returnarr[(rearIndex -1) %size];
48+
}
49+
50+
publicbooleanisEmpty() {
51+
returnrearIndex ==frontIndex;
52+
}
53+
54+
publicbooleanisFull() {
55+
returnMath.abs(rearIndex -frontIndex) ==size;
56+
}
57+
}
58+
59+
}
60+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._622;
4+
importorg.junit.Test;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
publicclass_622Test {
9+
privatestatic_622.Solution1.MyCircularQueuemyCircularQueue;
10+
11+
@Test
12+
publicvoidtest1() {
13+
myCircularQueue =new_622.Solution1.MyCircularQueue(3);
14+
assertEquals(true,myCircularQueue.enQueue(1));
15+
assertEquals(true,myCircularQueue.enQueue(2));
16+
assertEquals(true,myCircularQueue.enQueue(3));
17+
assertEquals(false,myCircularQueue.enQueue(4));
18+
assertEquals(3,myCircularQueue.Rear());
19+
assertEquals(true,myCircularQueue.isFull());
20+
assertEquals(true,myCircularQueue.deQueue());
21+
assertEquals(true,myCircularQueue.enQueue(4));
22+
assertEquals(4,myCircularQueue.Rear());
23+
}
24+
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp