Skip to content

style: add prettier and format code #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions .docsifytopdfrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
contents: ["summary.md"],
pathToPublic: "pdf/doocs-leetcode.pdf",
pdfOptions: "<options for puppeteer.pdf()>",
removeTemp: true,
emulateMedia: "screen",
contents: ["summary.md"],
pathToPublic: "pdf/doocs-leetcode.pdf",
pdfOptions: "<options for puppeteer.pdf()>",
removeTemp: true,
emulateMedia: "screen",
};
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"TrailingCooma": "all",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid"
}
6 changes: 3 additions & 3 deletions basic/sorting/BubbleSort/BubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ function bubbleSort(inputArr) {
let temp = inputArr[j];
inputArr[j] = inputArr[j + 1];
inputArr[j + 1] = temp;
swapped = true
swapped = true;
}
}
if (swapped === false) break;
}
return (inputArr)
return inputArr;
}

let arr = [6, 3, 2, 1, 5];
console.log(bubbleSort(arr))
console.log(bubbleSort(arr));
4 changes: 2 additions & 2 deletions basic/sorting/InsertionSort/InsertionSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function insertionSort(inputArr) {
}
inputArr[j + 1] = temp;
}
return (inputArr);
return inputArr;
}

let arr = [6, 3, 2, 1, 5];
console.log(insertionSort(arr))
console.log(insertionSort(arr));
24 changes: 12 additions & 12 deletions basic/sorting/MergeSort/Main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
var buf = '';
var buf = "";

process.stdin.on('readable', function () {
process.stdin.on("readable", function () {
var chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});

let getInputArgs = line => {
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
}
return line
.split(" ")
.filter(s => s !== "")
.map(x => parseInt(x));
};

function mergeSort(nums, left, right) {
if (left >= right) {
return;
}

const mid = (left + right) >> 1;
mergeSort(nums, left, mid);
mergeSort(nums, mid + 1, right);
Expand All @@ -38,15 +41,12 @@ function mergeSort(nums, left, right) {
}
}



process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
process.stdin.on("end", function () {
buf.split("\n").forEach(function (line, lineIdx) {
if (lineIdx % 2 === 1) {
nums = getInputArgs(line);
mergeSort(nums, 0, nums.length - 1);
console.log(nums.join(' '));
console.log(nums.join(" "));
}

});
});
});
24 changes: 12 additions & 12 deletions basic/sorting/QuickSort/Main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
var buf = '';
var buf = "";

process.stdin.on('readable', function () {
process.stdin.on("readable", function () {
var chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});

let getInputArgs = line => {
return line.split(' ').filter(s => s !== '').map(x => parseInt(x));
}
return line
.split(" ")
.filter(s => s !== "")
.map(x => parseInt(x));
};

function quickSort(nums, left, right) {
if (left >= right) {
return;
}

let i = left - 1;
let j = right + 1;
let x = nums[(left + right) >> 1];
Expand All @@ -30,15 +33,12 @@ function quickSort(nums, left, right) {
quickSort(nums, j + 1, right);
}



process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
process.stdin.on("end", function () {
buf.split("\n").forEach(function (line, lineIdx) {
if (lineIdx % 2 === 1) {
nums = getInputArgs(line);
quickSort(nums, 0, nums.length - 1);
console.log(nums.join(' '));
console.log(nums.join(" "));
}

});
});
});
5 changes: 2 additions & 3 deletions basic/sorting/SelectionSort/SelectionSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ function selectionSort(inputArr) {
let j = i;
let min = j;
while (j <= len - 1) {
if (inputArr[j] < inputArr[min])
min = j;
if (inputArr[j] < inputArr[min]) min = j;
j++;
}
let temp = inputArr[i];
Expand All @@ -16,4 +15,4 @@ function selectionSort(inputArr) {
}

let arr = [6, 3, 2, 1, 5];
console.log(selectionSort(arr))
console.log(selectionSort(arr));
2 changes: 1 addition & 1 deletion basic/sorting/ShellSort/ShellSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ function shellSort(arr) {
}

let arr = [6, 3, 2, 1, 5];
console.log(shellSort(arr))
console.log(shellSort(arr));
8 changes: 4 additions & 4 deletions lcci/01.01.Is Unique/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* @param {string} astr
* @return {boolean}
*/
var isUnique = function(astr) {
var isUnique = function (astr) {
let bitmap = 0;
for (let i = 0; i < astr.length; ++i) {
const pos = astr[i].charCodeAt() - 'a'.charCodeAt();
const pos = astr[i].charCodeAt() - "a".charCodeAt();
if ((bitmap & (1 << pos)) != 0) {
return false;
}
bitmap |= (1 << pos);
bitmap |= 1 << pos;
}
return true;
};
};
10 changes: 6 additions & 4 deletions lcci/01.02.Check Permutation/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* @param {string} s2
* @return {boolean}
*/
var CheckPermutation = function(s1, s2) {
let n1 = s1.length, n2 = s2.length;
var CheckPermutation = function (s1, s2) {
let n1 = s1.length,
n2 = s2.length;
if (n1 != n2) return false;
let counter = {};
for (let i = 0; i < n1; i++) {
let cur1 = s1.charAt(i), cur2 = s2.charAt(i);
let cur1 = s1.charAt(i),
cur2 = s2.charAt(i);
counter[cur1] = (counter[cur1] || 0) + 1;
counter[cur2] = (counter[cur2] || 0) - 1;
}
return Object.values(counter).every(v => v == 0);
};
};
6 changes: 3 additions & 3 deletions lcci/01.03.String to URL/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
* @param {number} length
* @return {string}
*/
var replaceSpaces = function(S, length) {
return encodeURI(S.substring(0,length));
};
var replaceSpaces = function (S, length) {
return encodeURI(S.substring(0, length));
};
13 changes: 7 additions & 6 deletions lcci/01.06.Compress String/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
* @param {string} S
* @return {string}
*/
var compressString = function(S) {
var compressString = function (S) {
if (!S) return S;
let p = 0, q = 1;
let res = '';
let p = 0,
q = 1;
let res = "";
while (q < S.length) {
if (S[p] != S[q]) {
res += (S[p] + (q - p));
res += S[p] + (q - p);
p = q;
}
++q;
}
res += (S[p] + (q - p));
res += S[p] + (q - p);
return res.length < S.length ? res : S;
};
};
6 changes: 3 additions & 3 deletions lcci/01.07.Rotate Matrix/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
var rotate = function(matrix) {
var rotate = function (matrix) {
const n = matrix.length;
for (let i = 0; i < (n / 2); i++) {
for (let i = 0; i < n / 2; i++) {
for (let j = i; j < n - i - 1; j++) {
let t = matrix[i][j];
matrix[i][j] = matrix[n - j - 1][i];
Expand All @@ -13,4 +13,4 @@
matrix[j][n - i - 1] = t;
}
}
};
};
7 changes: 4 additions & 3 deletions lcci/01.08.Zero Matrix/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
var setZeroes = function(matrix) {
let m = matrix.length, n = matrix[0].length;
var setZeroes = function (matrix) {
let m = matrix.length,
n = matrix[0].length;
let rows = new Array(m).fill(false);
let cols = new Array(n).fill(false);
// 标记
Expand All @@ -23,4 +24,4 @@
}
}
}
};
};
7 changes: 4 additions & 3 deletions lcci/02.01.Remove Duplicate Node/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* @param {ListNode} head
* @return {ListNode}
*/
var removeDuplicateNodes = function(head) {
var removeDuplicateNodes = function (head) {
if (head == null || head.next == null) return head;
const cache = new Set([]);
cache.add(head.val);
let cur = head, fast = head.next;
let cur = head,
fast = head.next;
while (fast !== null) {
if (!cache.has(fast.val)) {
cur.next = fast;
Expand All @@ -24,4 +25,4 @@
}
cur.next = null;
return head;
};
};
7 changes: 4 additions & 3 deletions lcci/02.02.Kth Node From End of List/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* @param {number} k
* @return {number}
*/
var kthToLast = function(head, k) {
let fast = head, slow = head;
var kthToLast = function (head, k) {
let fast = head,
slow = head;
for (let i = 0; i < k; i++) {
fast = fast.next;
}
Expand All @@ -20,4 +21,4 @@
slow = slow.next;
}
return slow.val;
};
};
8 changes: 4 additions & 4 deletions lcci/02.03.Delete Middle Node/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @param {ListNode} node
* @return {void} Do not return anything, modify node in-place instead.
*/
var deleteNode = function(node) {
node.val = node.next.val
node.next = node.next.next
};
var deleteNode = function (node) {
node.val = node.next.val;
node.next = node.next.next;
};
26 changes: 13 additions & 13 deletions lcci/02.05.Sum Lists/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
* @return {ListNode}
*/
var addTwoNumbers = function (l1, l2) {
let carry = 0;
const dummy = new ListNode(-1);
let cur = dummy;
while (l1 || l2 || carry) {
const s = (l1 ? l1.val : 0) + (l2 ? l2.val : 0) + carry;
carry = Math.floor(s / 10);
cur.next = new ListNode(s % 10);
cur = cur.next;
l1 = l1 ? l1.next : l1;
l2 = l2 ? l2.next : l2;
}
return dummy.next;
};
let carry = 0;
const dummy = new ListNode(-1);
let cur = dummy;
while (l1 || l2 || carry) {
const s = (l1 ? l1.val : 0) + (l2 ? l2.val : 0) + carry;
carry = Math.floor(s / 10);
cur.next = new ListNode(s % 10);
cur = cur.next;
l1 = l1 ? l1.next : l1;
l2 = l2 ? l2.next : l2;
}
return dummy.next;
};
Loading