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

Commit5877cab

Browse files
committed
add 69, 79, 82
1 parent48e15de commit5877cab

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

‎Medium/69-sqrtx.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
*@param {number} x
3+
*@return {number}
4+
*/
5+
varmySqrt=function(x){
6+
if(x===0)returnx;
7+
varleft=0;
8+
varright=x;
9+
varmid=Math.floor(x/2);
10+
while(left<=right){
11+
vardivideX=Math.floor(x/mid);
12+
// instead of using mid * mid > x, use x / mid incase overflow happens
13+
if(mid>divideX){
14+
right=mid-1;
15+
}else{
16+
left=mid+1;
17+
}
18+
mid=left+Math.floor((right-left)/2);
19+
}
20+
returnmid;
21+
};

‎Medium/79-wordSearch.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
*@param {character[][]} board
3+
*@param {string} word
4+
*@return {boolean}
5+
*/
6+
varexist=function(board,word){
7+
for(vari=0;i<board.length;i++){
8+
for(varj=0;j<board[0].length;j++){
9+
if(existHelper(board,word,i,j,0))returntrue;
10+
}
11+
}
12+
13+
returnfalse;
14+
};
15+
16+
// if the word[k] existing in board, keep searching up, down, left, right
17+
varexistHelper=function(board,word,i,j,k){
18+
if(k===word.length)returntrue;
19+
if(i<0||j<0||i>board.length-1||j>board[0].length-1)returnfalse;
20+
if(board[i][j]===word[k]){
21+
vartmp=board[i][j];
22+
board[i][j]='#';
23+
if(existHelper(board,word,i+1,j,k+1)||
24+
existHelper(board,word,i-1,j,k+1)||
25+
existHelper(board,word,i,j+1,k+1)||
26+
existHelper(board,word,i,j-1,k+1)){
27+
returntrue;
28+
}
29+
board[i][j]=tmp;
30+
}
31+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
/**
9+
*@param {ListNode} head
10+
*@return {ListNode}
11+
*/
12+
vardeleteDuplicates=function(head){
13+
if(!head||!head.next)returnhead;
14+
varpre=newListNode(null);
15+
pre.next=head;
16+
varpreCopy=pre;
17+
while(head.next){
18+
if(pre.next.val!==head.next.val){
19+
pre=pre.next;
20+
}else{
21+
while(head.next&&pre.next.val===head.next.val){
22+
head=head.next;
23+
}
24+
pre.next=head.next;
25+
}
26+
27+
if(head.next)head=head.next;
28+
}
29+
30+
returnpreCopy.next;
31+
};

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@
9595
*[59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/) -[Solution](./Medium/59-spiralMatrixII.js)
9696
*[61. Rotate List](https://leetcode.com/problems/rotate-list/) -[Solution](./Medium/61-rotateList.js)
9797
*[62.Unique Paths](https://leetcode.com/problems/unique-paths/) -[Solution](./Medium/62-uniquePaths.js)
98+
*[69. Sqrt(x)](https://leetcode.com/problems/sqrtx/) -[Solution](./Medium/69-sqrtx.js)
9899
*[64.Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/) -[Solution](./Medium/64-minimumPathSum.js)
99100
*[73. Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) -[Solution](./Medium/73-setMatrixZeroes.js)
100101
*[74. Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) -[Solution](./Medium/74-search2DMatrix.js)
101102
*[75. Sort Colors](https://leetcode.com/problems/sort-colors/) -[Solution](./Medium/75-sortColors.js)
102103
*[77.Combinations](https://leetcode.com/problems/combinations/) -[Solution](./Medium/77-combinations.js)
103104
*[78. Subsets](https://leetcode.com/problems/subsets/) -[Solution](./Medium/78-subsets.js)
105+
*[79. Word Search](https://leetcode.com/problems/word-search/) -[Solution](./Medium/79-wordSearch.js)
104106
*[80. Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) -[Solution](./Medium/80-removeDuplicatesII.js)
107+
*[82. Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/) -[Solution](./Medium/82-removeDuplicatesListII.js)
105108
*[89. Gray Code](https://leetcode.com/problems/gray-code/) -[Solution](./Medium/89-grayCode.js)
106109
*[92. Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) -[Solution](./Medium/92-reverseLinkedListII.js)
107110
*[94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) -[Solution](./Medium/94-binaryTreeInorder.js)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp