Skip to content

Commit 417c379

Browse files
committed
Add the JavaScript solutions
1 parent 035972c commit 417c379

File tree

61 files changed

+5321
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5321
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
107+
.vscode

.jshintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"eqnull":true,
5+
"nocomma": false,
6+
"undef": true,
7+
"unused": true,
8+
"strict": true,
9+
"esversion": 6,
10+
"quotmark": "single",
11+
"shadow": "outer",
12+
"jasmine": true,
13+
"module": true,
14+
"node": true
15+
}

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# LeetCode
2+
The JavaScript solutions for LeetCode problems.
3+
4+
### Algorithm
5+
6+
| Languages | Build Status | Solved Problems |
7+
| --------- | ------------ | --------------- |
8+
|JavaScript|[![Windows Build Status](https://img.shields.io/appveyor/ci/bigegg/leetcode-he0qs.svg?style=flat-square&label=Windows%20Build)](https://ci.appveyor.com/project/BigEgg/leetcode-he0qs)[![Linux Build Status](https://img.shields.io/badge/Linux%20Build-Invalid-lightgrey.svg?style=flat-square)]()|[![Solved Problems](https://img.shields.io/badge/Solved%20Problems-26-blue.svg?style=flat-square)](https://github.com/BigEgg/LeetCode/tree/JavaScript)|
9+
10+
## Problems
11+
12+
### Table of Contents
13+
* [001-050](#Problems-001-050)
14+
* [051-100](#Problems-051-100)
15+
* [101-150](#Problems-101-150)
16+
* [151-200](#Problems-151-200)
17+
* [201-250](#Problems-201-250)
18+
* [301-350](#Problems-301-350)
19+
* [551-600](#Problems-551-600)
20+
21+
### Problems 001-050
22+
[Back to Table of Contents](#Table-of-Contents)
23+
24+
| # | Title | Solutions | Time | Space | Comments |
25+
|---| ----- | --------- | ---- | ----- | -------- |
26+
| 1 | Two Sum | [JavaScript](./src/0001-0050/0001-TwoSum.js)(72ms) | O(N) | O(N) | |
27+
| 2 | Add Two Numbers | [JavaScript](./src/0001-0050/002-AddTwoNumbers.js)(260ms) | O(Max(N, M)) | O(1) | |
28+
| 3 | Longest Substring Without Repeating Characters | [JavaScript](./src/0001-0050/003-LongestSubstringWithoutRepeatingCharacters.js)(240ms) | O(N) | O(1) | C# use array will slower |
29+
| 4 | Median of Two Sorted Arrays | [JavaScript](./src/0001-0050/0004-MedianOfTwoSortedArrays.js)(128ms) | O(Log(N+M)) | O(1) | |
30+
| 5 | Longest Palindromic Substring | [JavaScript](./src/0001-0050/005-LongestPalindromicSubstring.js)(128ms) | O(N) | O(N) | Use Manacher's Algorithm |
31+
| 6 | ZigZag Conversion | [JavaScript](./src/0001-0050/006-ZigZagConversion.js)(188ms) | O(N) | O(N) | |
32+
| 7 | Reverse Integer | [JavaScript](./src/0001-0050/007-ReverseInteger.js)(129ms) | O(1) | O(1) | |
33+
| 8 | String to Integer (atoi) | [JavaScript](./src/0001-0050/008-StringToInteger(atoi).js)(122ms) | O(1) | O(1) | |
34+
| 9 | Palindrome Number | [JavaScript](./src/0001-0050/009-PalindromeNumber.js)(315ms) | O(1) | O(1) | |
35+
| 10 | Regular Expression Matching | [JavaScript](./src/0001-0050/010-RegularExpressionMatching.js)(276ms) | O(N*M) | O(N*M) | |
36+
| 11 | Container With Most Water | [JavaScript](./src/0001-0050/0011-ContainerWithMostWater.js)(80ms) | O(N) | O(1) | |
37+
| 15 | 3Sum | [JavaScript](./src/0001-0050/0015-3Sum.js)(128ms) | O(N<sup>2</sup>) | O(M) | For Python solution, use count to reduce time to O(min(N, M<sup>2</sup>)) and space to O(M) |
38+
| 31 | Next Permutation | [JavaScript](./src/0001-0050/0031-NextPermutation.js)(76ms) | O(N) | O(1) | |
39+
| 33 | Search in Rotated Sorted Array | [JavaScript](./src/0001-0050/0033-SearchInRotatedSortedArray.js)(68ms) | O(N) | O(1) | |
40+
| 42 | Trapping Rain Water | [JavaScript](./src/0001-0050/0042-TrappingRainWater.js)(80ms) | O(N) | O(1) | |
41+
42+
### Problems 051-100
43+
[Back to Table of Contents](#Table-of-Contents)
44+
45+
| # | Title | Solutions | Time | Space | Comments |
46+
|---| ----- | --------- | ---- | ----- | -------- |
47+
| 53 | Maximum Subarray | [JavaScript](./src/0051-0100/0053-MaximumSubarray.js)(72ms) | O(N) | O(1) | |
48+
| 56 | Merge Intervals | [JavaScript](./src/0051-0100/0056-MergeIntervals.js)(88ms) | O(NLogN) | O(1) | |
49+
| 84 | Largest Rectangle in Histogram | [JavaScript](./src/0051-0100/0084-LargestRectangleInHistogram.js)(84ms) | O(N) | O(N) | |
50+
| 85 | Maximal Rectangle | [JavaScript](./src/0051-0100/0085-MaximalRectangle.js)(88ms) | O(N*M) | O(M) | |
51+
52+
### Problems 101-150
53+
[Back to Table of Contents](#Table-of-Contents)
54+
55+
| # | Title | Solutions | Time | Space | Comments |
56+
|---| ----- | --------- | ---- | ----- | -------- |
57+
| 121 | Best Time to Buy and Sell Stock | [JavaScript](./src/0101-0150/0121-BestTimeToBuyAndSellStock.js)(80ms) | O(N) | O(1) | |
58+
| 127 | Word Ladder | [JavaScript](./src/0101-0150/0127-WordLadder.js)(120ms) | O(N*M) | O(N*M) | Bidirectional BFS |
59+
60+
### Problems 151-200
61+
[Back to Table of Contents](#Table-of-Contents)
62+
63+
| # | Title | Solutions | Time | Space | Comments |
64+
|---| ----- | --------- | ---- | ----- | -------- |
65+
| 199 | Binary Tree Right Side View | [JavaScript](./src/0151-0200/0199-BinaryTreeRightSideView.js)(76ms) | O(N) | O(h) | |
66+
| 200 | Number of Islands | [JavaScript](./src/0151-0200/0200-NumberOfIslands.js)(96ms) | O(N*M) | O(N*M) | |
67+
68+
### Problems 201-250
69+
[Back to Table of Contents](#Table-of-Contents)
70+
71+
| # | Title | Solutions | Time | Space | Comments |
72+
|---| ----- | --------- | ---- | ----- | -------- |
73+
| 238 | Product of Array Except Self | [JavaScript](./src/0201-0250/0238-ProductOfArrayExceptSelf.js)(92ms) | O(N) | O(1) | |
74+
75+
### Problems 301-350
76+
[Back to Table of Contents](#Table-of-Contents)
77+
78+
| # | Title | Solutions | Time | Space | Comments |
79+
|---| ----- | --------- | ---- | ----- | -------- |
80+
| 301 | Remove Invalid Parentheses | [JavaScript](./src/0301-0350/0301-RemoveInvalidParentheses.js)(80ms) | O(2<sup>N</sup>) | O(N) | |
81+
82+
### Problems 551-600
83+
[Back to Table of Contents](#Table-of-Contents)
84+
85+
| # | Title | Solutions | Time | Space | Comments |
86+
|---| ----- | --------- | ---- | ----- | -------- |
87+
| 560 | Subarray Sum Equals K | [JavaScript](./src/0551-0600/0560-SubarraySumEqualsK.js)(120ms) | O(N) | O(1) | |

jasmine-runner.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
let Jasmine = require('jasmine');
4+
let SpecReporter = require('jasmine-spec-reporter').SpecReporter;
5+
6+
let jrunner = new Jasmine();
7+
jrunner.env.clearReporters(); // remove default reporter logs
8+
jrunner.addReporter(new SpecReporter({ // add jasmine-spec-reporter
9+
spec: {
10+
displayPending: true
11+
}
12+
}));
13+
jrunner.loadConfigFile(); // load jasmine.json configuration
14+
jrunner.execute();

0 commit comments

Comments
 (0)