Skip to content

Commit 95abef5

Browse files
Restyled by clang-format
1 parent 42626a6 commit 95abef5

25 files changed

+87
-79
lines changed

Diff for: javascript/1-easy-two-sum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const twoSum = (nums, target) => {
1010
return result;
1111
};
1212

13-
twoSum([2, 7, 11, 15], 9);
13+
twoSum([ 2, 7, 11, 15 ], 9);

Diff for: javascript/11-container-with-most-water.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var maxArea = function(height) {
1414
// Update the maximum area
1515
maxArea = Math.max(maxArea, currentArea);
1616

17-
//Move the pointer with the smaller height
17+
// Move the pointer with the smaller height
1818
if (height[left] < height[right]) {
1919
left++;
2020
} else {

Diff for: javascript/125-validPalindrom.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @param {string} s
1515
* @return {boolean}
1616
*/
17-
var isPalindrome = function (s) {
17+
var isPalindrome = function(s) {
1818
let str = s.toLowerCase();
1919
let finalStr = '';
2020
for (let i = 0; i < str.length; i++) {
@@ -23,15 +23,18 @@ var isPalindrome = function (s) {
2323
finalStr += str[i];
2424
}
2525
}
26-
if (finalStr === finalStr.split('').reverse().join('')) return true;
26+
if (finalStr === finalStr.split('').reverse().join(''))
27+
return true;
2728
return false;
2829
};
2930

3031
const checkAsciiValue = (value) => {
31-
if (value.charCodeAt(0) >= 97 && value.charCodeAt(0) <= 122) return true;
32-
if (value.charCodeAt(0) >= 48 && value.charCodeAt(0) <= 57) return true;
32+
if (value.charCodeAt(0) >= 97 && value.charCodeAt(0) <= 122)
33+
return true;
34+
if (value.charCodeAt(0) >= 48 && value.charCodeAt(0) <= 57)
35+
return true;
3336
return false;
3437
};
3538

3639
console.log(isPalindrome('A man, a plan, a canal: Panama'));
37-
//console.log(isPalindrome('0p'));
40+
// console.log(isPalindrome('0p'));

Diff for: javascript/13-easy-romatToInt.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const romanToInt = (s) => {
22
const roman = {
3-
I: 1,
4-
V: 5,
5-
X: 10,
6-
L: 50,
7-
C: 100,
8-
D: 500,
9-
M: 1000,
3+
I : 1,
4+
V : 5,
5+
X : 10,
6+
L : 50,
7+
C : 100,
8+
D : 500,
9+
M : 1000,
1010
};
1111
let sum = 0;
1212
for (let i = 0; i < s.length; i++) {

Diff for: javascript/136-singleNumber.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @param {number[]} nums
33
* @return {number}
44
*/
5-
var singleNumber = function (nums) {
5+
var singleNumber = function(nums) {
66
let length = nums.length;
77
let uniqueVal;
88
for (let i = 0; i < length; i++) {
@@ -16,4 +16,4 @@ var singleNumber = function (nums) {
1616
return uniqueVal;
1717
};
1818

19-
console.log(singleNumber([4, 1, 2, 1, 2]));
19+
console.log(singleNumber([ 4, 1, 2, 1, 2 ]));

Diff for: javascript/14-easy-longestCommonPrefix.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
const longestCommonPrefix = (strs) => {
2-
if (strs.length === 0) return '';
2+
if (strs.length === 0)
3+
return '';
34
let result = '';
45
for (let i = 0; i < strs[0].length; i++) {
56
for (let j = 1; j < strs.length; j++) {
6-
if (strs[j][i] !== strs[0][i]) return result;
7+
if (strs[j][i] !== strs[0][i])
8+
return result;
79
}
810
result += strs[0][i];
911
}
1012
return result;
1113
};
1214

13-
console.log(longestCommonPrefix(['flower', 'flow', 'flight']));
15+
console.log(longestCommonPrefix([ 'flower', 'flow', 'flight' ]));

Diff for: javascript/20-easy-validParenthesis.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const isValid = (str) => {
2-
if (str.length % 2 !== 0) return false;
2+
if (str.length % 2 !== 0)
3+
return false;
34
const stack = [];
45
const map = {
5-
'(': ')',
6-
'[': ']',
7-
'{': '}',
6+
'(' : ')',
7+
'[' : ']',
8+
'{' : '}',
89
};
910
for (let i = 0; i < str.length; i++) {
1011
if (str[i] === '(' || str[i] === '[' || str[i] === '{') {

Diff for: javascript/205-isomorphicCharacter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var isIsomorphic = function (s, t) {
2+
var isIsomorphic = function(s, t) {
33
let map = new Map();
44
let map2 = new Map();
55
for (let i = 0; i < s.length; i++) {
@@ -16,5 +16,5 @@ var isIsomorphic = function (s, t) {
1616
};
1717

1818
console.log(isIsomorphic('egg', 'add'));
19-
//console.log(isIsomorphic('ffo', 'bar'));
20-
//console.log(isIsomorphic('paper', 'title'));
19+
// console.log(isIsomorphic('ffo', 'bar'));
20+
// console.log(isIsomorphic('paper', 'title'));

Diff for: javascript/21-easy-mergeTwoSortedList.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const mergeTwoLists = (l1, l2) => {
2-
if (!l1) return l2;
3-
if (!l2) return l1;
2+
if (!l1)
3+
return l2;
4+
if (!l2)
5+
return l1;
46
if (l1.val < l2.val) {
57
l1.next = mergeTwoLists(l1.next, l2);
68
return l1;
@@ -9,4 +11,4 @@ const mergeTwoLists = (l1, l2) => {
911
return l2;
1012
};
1113

12-
console.log(mergeTwoLists([1, 2, 4], [1, 3, 4]));
14+
console.log(mergeTwoLists([ 1, 2, 4 ], [ 1, 3, 4 ]));

Diff for: javascript/217-containsDuplicate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
* @param {number[]} nums
2323
* @return {boolean}
2424
*/
25-
var containsDuplicate = function (nums) {
25+
var containsDuplicate = function(nums) {
2626
let unique = new Set(nums);
2727
return unique.size !== nums.length;
2828
};
2929

30-
console.log(containsDuplicate([1, 2, 3, 4]));
30+
console.log(containsDuplicate([ 1, 2, 3, 4 ]));

Diff for: javascript/26-easy-removeDuplicates.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var removeDuplicates = function (nums) {
2+
var removeDuplicates = function(nums) {
33
let i = 0;
44
while (i < nums.length) {
55
if (nums[i] === nums[i + 1]) {
@@ -10,4 +10,4 @@ var removeDuplicates = function (nums) {
1010
}
1111
return nums.length;
1212
};
13-
console.log(removeDuplicates([0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4]));
13+
console.log(removeDuplicates([ 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4 ]));

Diff for: javascript/260-singleNumber2.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* @param {number[]} nums
33
* @return {number}
44
*/
5-
var singleNumber = function (nums) {
5+
var singleNumber = function(nums) {
66
let length = nums.length;
7-
let uniqueVal=[];
7+
let uniqueVal = [];
88
for (let i = 0; i < length; i++) {
99
let unique = nums.filter((item) => item === nums[i]);
1010
if (unique.length === 1) {
@@ -15,4 +15,4 @@ var singleNumber = function (nums) {
1515
return uniqueVal;
1616
};
1717

18-
console.log(singleNumber([1,2,1,3,2,5]));
18+
console.log(singleNumber([ 1, 2, 1, 3, 2, 5 ]));

Diff for: javascript/2620-counter.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @param {number} n
33
* @return {Function} counter
44
*/
5-
var createCounter = function (n) {
5+
var createCounter = function(n) {
66
let count = n;
77

88
function counter() {
@@ -16,9 +16,9 @@ var createCounter = function (n) {
1616

1717
const counter = createCounter(5);
1818

19-
console.log(counter()); // Output: 5
20-
console.log(counter()); // Output: 6
21-
console.log(counter()); // Output: 7
22-
console.log(counter()); // Output: 8
23-
console.log(counter()); // Output: 9
24-
console.log(counter()); // Output: 10
19+
console.log(counter()); // Output: 5
20+
console.log(counter()); // Output: 6
21+
console.log(counter()); // Output: 7
22+
console.log(counter()); // Output: 8
23+
console.log(counter()); // Output: 9
24+
console.log(counter()); // Output: 10

Diff for: javascript/2667.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
22
* @return {Function}
33
*/
4-
var createHelloWorld = function () {
5-
return function (...args) {
6-
return 'Hello World';
7-
};
8-
};
4+
var createHelloWorld =
5+
function() { return function(...args) { return 'Hello World'; }; };

Diff for: javascript/27-easy-removeElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var removeElement = function (nums, val) {
1+
var removeElement = function(nums, val) {
22
for (let i = 0; i < nums.length; i++) {
33
if (nums[i] === val) {
44
nums.splice(i, 1);

Diff for: javascript/2704-to-be-or-not-be.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
* @param {string} val
33
* @return {Object}
44
*/
5-
var expect = function (val) {
5+
var expect = function(val) {
66
return {
7-
toBe: function (expected) {
8-
if (val === expected) return true;
7+
toBe : function(expected) {
8+
if (val === expected)
9+
return true;
910
throw new Error('Not Equal');
1011
},
11-
notToBe: function (expected) {
12-
if (val !== expected) return true;
12+
notToBe : function(expected) {
13+
if (val !== expected)
14+
return true;
1315
throw new Error('Equal');
1416
},
1517
};

Diff for: javascript/344-reverseString.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @param {character[]} s
33
* @return {void} Do not return anything, modify s in-place instead.
44
*/
5-
var reverseString = function (s) {
5+
var reverseString = function(s) {
66
let left = 0;
77
let right = s.length - 1;
88
while (left < right) {
@@ -16,4 +16,4 @@ var reverseString = function (s) {
1616
return s;
1717
};
1818

19-
console.log(reverseString(["h", "e", "l", "l", "o"]));
19+
console.log(reverseString([ "h", "e", "l", "l", "o" ]));

Diff for: javascript/35-easy-searchInsertPosition.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ const searchInsert = (nums, target) => {
1313
}
1414
};
1515

16-
console.log(searchInsert([1, 3, 5, 6], 7)); // 2
16+
console.log(searchInsert([ 1, 3, 5, 6 ], 7)); // 2

Diff for: javascript/3_longest_substring.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
//3. Longest Substring Without Repeating Characters
2-
// Given a string, find the length of the longest substring without repeating characters.
3-
// Example 1:
4-
// Input: "abcabcbb"
5-
// Output: 3
6-
// Explanation: The answer is "abc", with the length of 3.
1+
// 3. Longest Substring Without Repeating Characters
2+
// Given a string, find the length of the longest substring without repeating
3+
// characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer
4+
// is "abc", with the length of 3.
75

86
/**
97
* @param {string} s
108
* @return {number}
119
*/
12-
var lengthOfLongestSubstring = function (s) {
10+
var lengthOfLongestSubstring = function(s) {
1311
let longest = 0;
1412
let seen = {};
1513
let start = 0;
1614

1715
for (let i = 0; i < s.length; i++) {
1816
let char = s[i];
19-
if (seen[char]) start = Math.max(start, seen[char]);
17+
if (seen[char])
18+
start = Math.max(start, seen[char]);
2019

2120
longest = Math.max(longest, i - start + 1);
2221
seen[char] = i + 1;

Diff for: javascript/4-findMedianSortedArrays.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* @param {number[]} nums2
44
* @return {number}
55
*/
6-
var findMedianSortedArrays = function (nums1, nums2) {
6+
var findMedianSortedArrays = function(nums1, nums2) {
77
let nums = nums1.concat(nums2);
88
nums.sort((a, b) => a - b);
99
let len = nums.length;
1010
let mid = Math.floor(len / 2);
1111
return len % 2 === 0 ? (nums[mid] + nums[mid - 1]) / 2 : nums[mid];
1212
};
1313

14-
findMedianSortedArrays([1, 2], [3, 4]);
14+
findMedianSortedArrays([ 1, 2 ], [ 3, 4 ]);

Diff for: javascript/66-easy-plusOne.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ const plusOne = (digits) => {
1111
return digits;
1212
};
1313

14-
plusOne([9,9]);
14+
plusOne([ 9, 9 ]);

Diff for: javascript/67-addBinary.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const addBinary = (a, b) => {
2-
let sum = '',
3-
carry = 0;
2+
let sum = '', carry = 0;
43

54
a = a.split('');
65
b = b.split('');
@@ -12,7 +11,8 @@ const addBinary = (a, b) => {
1211
sum = (temp % 2) + sum;
1312
carry = Math.floor(temp / 2);
1413
}
15-
if (carry) sum = carry + sum;
14+
if (carry)
15+
sum = carry + sum;
1616

1717
return sum;
1818
};

Diff for: javascript/69-Sqrt.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// return Math.floor(Math.sqrt(x));
77
// };
88

9-
var mySqrt = function (x) {
9+
var mySqrt = function(x) {
1010
let i = 1;
1111
let sqr = i * i;
1212

Diff for: javascript/88-margSortedArray.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
33
Output: [1,2,2,3,5,6]
44
Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
5-
The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
5+
The result of the merge is [1,2,2,3,5,6] with the underlined elements coming
6+
from nums1.
67
*/
78

8-
var merge = function (nums1, m, nums2, n) {
9-
var index = m + n - 1; //last index
9+
var merge = function(nums1, m, nums2, n) {
10+
var index = m + n - 1; // last index
1011
while (n > 0) {
1112
if (m > 0 && nums1[m - 1] > nums2[n - 1]) {
1213
nums1[index] = nums1[m - 1];
@@ -19,4 +20,4 @@ var merge = function (nums1, m, nums2, n) {
1920
}
2021
};
2122

22-
console.log(merge([1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3));
23+
console.log(merge([ 1, 2, 3, 0, 0, 0 ], 3, [ 2, 5, 6 ], 3));

Diff for: javascript/P-Array-AddNumberFromArray.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @param {ListNode} l2
1111
* @return {ListNode}
1212
*/
13-
var addTwoNumbers = function (l1, l2) {
13+
var addTwoNumbers = function(l1, l2) {
1414
let len = l1.length > l2.length ? l1.length : l2.length;
1515
let sLen = l1.length < l2.length ? l1.length : l2.length;
1616
let carry = 0;
@@ -36,8 +36,9 @@ var addTwoNumbers = function (l1, l2) {
3636
}
3737
}
3838
}
39-
if (carry > 0) sum.push(carry);
39+
if (carry > 0)
40+
sum.push(carry);
4041
return sum;
4142
};
4243

43-
addTwoNumbers([2, 4, 3], [5, 6, 4]);
44+
addTwoNumbers([ 2, 4, 3 ], [ 5, 6, 4 ]);

0 commit comments

Comments
 (0)