Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a21b1e8
Create Solution.js
07subhadip Sep 23, 2024
324cc2b
Create Solution.js
07subhadip Sep 23, 2024
80634a8
Update Solution.js
yanglbme Sep 24, 2024
3680e8b
Delete solution/Solution.js
yanglbme Sep 24, 2024
7a18121
Update README.md
yanglbme Sep 24, 2024
46a2880
Update README_EN.md
yanglbme Sep 24, 2024
f4825db
Create Solution.js
07subhadip Sep 24, 2024
8c24319
Update Solution.ts
07subhadip Sep 24, 2024
d6f4c63
Merge branch 'main' into main
yanglbme Sep 24, 2024
9223b1f
style: format code and docs with prettier
yanglbme Sep 24, 2024
fa67038
Update Solution.ts
yanglbme Sep 24, 2024
cc15596
Update Solution.js
yanglbme Sep 24, 2024
313f6b5
Update README.md
yanglbme Sep 24, 2024
63ef10d
Update README_EN.md
yanglbme Sep 24, 2024
6ae183c
Create Solution.js
07subhadip Sep 25, 2024
5f7be59
Merge branch 'doocs:main' into main
07subhadip Sep 25, 2024
f77f588
style: format code and docs with prettier
07subhadip Sep 25, 2024
1b9ab60
Update README.md
yanglbme Sep 25, 2024
8b4d469
Update README_EN.md
yanglbme Sep 25, 2024
bf35864
Merge branch 'main' into main
acbin Sep 25, 2024
cb0c193
Create Solution.js
07subhadip Sep 26, 2024
5927c3d
Merge branch 'main' into main
yanglbme Sep 26, 2024
a4b0a17
style: format code and docs with prettier
yanglbme Sep 26, 2024
a5b3b01
Update README.md
yanglbme Sep 26, 2024
4316b1e
Update README_EN.md
yanglbme Sep 26, 2024
f5ef073
Create Solution.js
07subhadip Sep 27, 2024
279136f
Merge branch 'main' into main
yanglbme Sep 27, 2024
5ac3684
style: format code and docs with prettier
yanglbme Sep 27, 2024
6a90290
Update README.md
yanglbme Sep 27, 2024
59d7872
Update README_EN.md
yanglbme Sep 27, 2024
14bb493
Create Solution.js
07subhadip Sep 28, 2024
fc6e992
Create Solution2.js
07subhadip Sep 28, 2024
6d9e162
Create Solution.js
07subhadip Sep 28, 2024
e221a03
Create Solution.js
07subhadip Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions solution/0000-0099/0045.Jump Game II/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @param {number[]} nums
* @return {number}
*/
var jump = function(nums) {
let jumps = 0;
let currentEnd = 0;
let farthest = 0;

for (let i = 0; i < nums.length - 1; i++) {
farthest = Math.max(farthest, i + nums[i]);

if (i === currentEnd) {
jumps++;
currentEnd = farthest;
}
}

return jumps;
};
14 changes: 14 additions & 0 deletions solution/0100-0199/0119.Pascal's Triangle II/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param {number} rowIndex
* @return {number[]}
*/
var getRow = function(rowIndex) {
const f = Array(rowIndex + 1).fill(1);
for (let i = 2; i < rowIndex + 1; ++i) {
for (let j = i - 1; j > 0; --j) {
f[j] += f[j - 1];
}
}
return f;

};
97 changes: 97 additions & 0 deletions solution/0600-0699/0641.Design Circular Deque/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* @param {number} k
*/
var MyCircularDeque = function(k) {
this.size = k;
this.deque = new Array(k);
this.front = 0;
this.rear = 0;
this.count = 0;
};

/**
* @param {number} value
* @return {boolean}
*/
MyCircularDeque.prototype.insertFront = function(value) {
if (this.isFull()) return false;
this.front = (this.front - 1 + this.size) % this.size;
this.deque[this.front] = value;
this.count++;
return true;
};

/**
* @param {number} value
* @return {boolean}
*/
MyCircularDeque.prototype.insertLast = function(value) {
if (this.isFull()) return false;
this.deque[this.rear] = value;
this.rear = (this.rear + 1) % this.size;
this.count++;
return true;
};

/**
* @return {boolean}
*/
MyCircularDeque.prototype.deleteFront = function() {
if (this.isEmpty()) return false;
this.front = (this.front + 1) % this.size;
this.count--;
return true;
};

/**
* @return {boolean}
*/
MyCircularDeque.prototype.deleteLast = function() {
if (this.isEmpty()) return false;
this.rear = (this.rear - 1 + this.size) % this.size;
this.count--;
return true;
};

/**
* @return {number}
*/
MyCircularDeque.prototype.getFront = function() {
if (this.isEmpty()) return -1;
return this.deque[this.front];
};

/**
* @return {number}
*/
MyCircularDeque.prototype.getRear = function() {
if (this.isEmpty()) return -1;
return this.deque[(this.rear - 1 + this.size) % this.size];
};

/**
* @return {boolean}
*/
MyCircularDeque.prototype.isEmpty = function() {
return this.count === 0;
};

/**
* @return {boolean}
*/
MyCircularDeque.prototype.isFull = function() {
return this.count === this.size;
};

/**
* Your MyCircularDeque object will be instantiated and called as such:
* var obj = new MyCircularDeque(k)
* var param_1 = obj.insertFront(value)
* var param_2 = obj.insertLast(value)
* var param_3 = obj.deleteFront()
* var param_4 = obj.deleteLast()
* var param_5 = obj.getFront()
* var param_6 = obj.getRear()
* var param_7 = obj.isEmpty()
* var param_8 = obj.isFull()
*/
37 changes: 37 additions & 0 deletions solution/0700-0799/0731.My Calendar II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
*/
```

#### JavaScript

```js
var MyCalendarTwo = function () {
this.events = [];
this.overlaps = [];
};

/**
* @param {number} start
* @param {number} end
* @return {boolean}
*/
MyCalendarTwo.prototype.book = function (start, end) {
for (let [s, e] of this.overlaps) {
if (Math.max(start, s) < Math.min(end, e)) {
return false;
}
}

for (let [s, e] of this.events) {
if (Math.max(start, s) < Math.min(end, e)) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
}
}

this.events.push([start, end]);
return true;
};

/**
* Your MyCalendarTwo object will be instantiated and called as such:
* var obj = new MyCalendarTwo()
* var param_1 = obj.book(start,end)
*/
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
37 changes: 37 additions & 0 deletions solution/0700-0799/0731.My Calendar II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
*/
```

#### JavaScript

```js
var MyCalendarTwo = function () {
this.events = [];
this.overlaps = [];
};

/**
* @param {number} start
* @param {number} end
* @return {boolean}
*/
MyCalendarTwo.prototype.book = function (start, end) {
for (let [s, e] of this.overlaps) {
if (Math.max(start, s) < Math.min(end, e)) {
return false;
}
}

for (let [s, e] of this.events) {
if (Math.max(start, s) < Math.min(end, e)) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
}
}

this.events.push([start, end]);
return true;
};

/**
* Your MyCalendarTwo object will be instantiated and called as such:
* var obj = new MyCalendarTwo()
* var param_1 = obj.book(start,end)
*/
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
32 changes: 32 additions & 0 deletions solution/0700-0799/0731.My Calendar II/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var MyCalendarTwo = function () {
this.events = [];
this.overlaps = [];
};

/**
* @param {number} start
* @param {number} end
* @return {boolean}
*/
MyCalendarTwo.prototype.book = function (start, end) {
for (let [s, e] of this.overlaps) {
if (Math.max(start, s) < Math.min(end, e)) {
return false;
}
}

for (let [s, e] of this.events) {
if (Math.max(start, s) < Math.min(end, e)) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
}
}

this.events.push([start, end]);
return true;
};

/**
* Your MyCalendarTwo object will be instantiated and called as such:
* var obj = new MyCalendarTwo()
* var param_1 = obj.book(start,end)
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {number[]} arr
* @return {boolean}
*/
var canMakeArithmeticProgression = function(arr) {
arr.sort((a,b)=>a-b)

let val = arr[1] - arr [0]

for(let i = 1 ; i < arr.length-1 ; i++){
if(arr[i+1]-arr[i] !== val){
return false
}
}

return true
};
Loading