1
1
# leetcode-cli-plugins
2
- 3rd party plugins for leetcode-cli
2
+ 3rd party plugins for leetcode-cli.
3
3
4
- | Plugin| Description|
5
- | -| -|
6
- | company.js| Filter question by company tag.|
7
- | cpp.lint.js| Run cpplint to check syntax before running test.|
8
- | cpp.run.js| Run cpp code locally for debugging purpose.|
4
+ * [ company.js] ( #company )
5
+ * [ cpp.lint.js] ( #cpp.lint )
6
+ * [ cpp.run.js] ( #cpp.run )
7
+ * [ solution.discuss] ( #solution.discuss )
9
8
10
9
## HOWTO
11
10
@@ -15,10 +14,104 @@ You can install the plugins in either ways below:
15
14
16
15
$ leetcode install <plugin file>
17
16
18
- ### Manually Install
17
+ To manage the installed plugins, please check [ leetcode-cli's user guide ] ( https://skygragon.github.io/leetcode-cli/commands#plugin ) .
19
18
20
- Copy the plugin file to the sub folder ` lib/plugins/ ` where leetcode-cli installed.
19
+ ## Plugins
21
20
22
- E.g. On Linux/Mac, the path would be like: ` /usr/local/lib/node_modules/leetcode-cli/lib/plugins/ `
21
+ ### Company
23
22
24
- Tips: You can find the path by running ` npm ` , check the last line of the output.
23
+ * use ` list ` + ` -t ` to filter by company.
24
+
25
+ Filter questions by company tag.
26
+
27
+ $ leetcode list -q hL -t facebook
28
+
29
+ [410] Split Array Largest Sum Hard (36.60 %)
30
+ ✔ [301] Remove Invalid Parentheses Hard (35.03 %)
31
+ ✔ [297] Serialize and Deserialize Binary Tree Hard (33.12 %)
32
+ [282] Expression Add Operators Hard (29.55 %)
33
+ [273] Integer to English Words Hard (21.98 %)
34
+ [218] The Skyline Problem Hard (27.00 %)
35
+ ✔ [146] LRU Cache Hard (17.53 %)
36
+ ✔ [128] Longest Consecutive Sequence Hard (36.63 %)
37
+ ✔ [ 85] Maximal Rectangle Hard (27.66 %)
38
+ ✔ [ 76] Minimum Window Substring Hard (25.14 %)
39
+ ✔ [ 68] Text Justification Hard (18.95 %)
40
+ ✔ [ 57] Insert Interval Hard (27.46 %)
41
+ ✔ [ 44] Wildcard Matching Hard (19.93 %)
42
+ ✔ [ 25] Reverse Nodes in k-Group Hard (30.61 %)
43
+ ✔ [ 23] Merge k Sorted Lists Hard (27.08 %)
44
+ ✔ [ 10] Regular Expression Matching Hard (24.06 %)
45
+
46
+ ### cpp.lint
47
+
48
+ Run cpplint to check c++ code syntax before running test.
49
+
50
+ $ leetcode test 1.two-sum.cpp
51
+
52
+ Input data:
53
+ [3,2,4]
54
+ 6
55
+
56
+ Running cpplint ...
57
+
58
+ [ERROR] 1.two-sum.cpp:29: public: should be indented +1 space inside class Solution [whitespace/indent] [3]
59
+ [ERROR] 1.two-sum.cpp:30: Is this a non-const reference? If so, make const or use a pointer: vector<int>& nums [runtime/references] [2]
60
+ [ERROR] 1.two-sum.cpp:31: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
61
+ [ERROR] 1.two-sum.cpp:31: Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2]
62
+ [ERROR] 1.two-sum.cpp:31: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3]
63
+
64
+
65
+ ### cpp.run
66
+
67
+ * use ` test ` + ` --local ` to test your code locally without asking leetcode.com.
68
+
69
+ Testing cpp code locally for debugging purpose.
70
+
71
+ $ leetcode test 001.two-sum.cpp --local
72
+
73
+ Input data:
74
+ [3,2,4]
75
+ 6
76
+
77
+ Testing locally ...
78
+
79
+ [1,2]
80
+
81
+ ### solution.discuss
82
+
83
+ * use ` show ` + ` --solution ` to display most voted solution.
84
+ * ` -l java ` to fetch java solution.
85
+
86
+ Fetch the most voted solution in discussion topics.
87
+
88
+ $ leetcode show 1 --solution
89
+
90
+ Accepted C++ O(n) Solution
91
+
92
+ https://discuss.leetcode.com/topic/3294/accepted-c-o-n-solution
93
+
94
+ * Lang: cpp
95
+ * Votes: 221
96
+
97
+ vector<int> twoSum(vector<int> &numbers, int target)
98
+ {
99
+ //Key is the number and value is its index in the vector.
100
+ unordered_map<int, int> hash;
101
+ vector<int> result;
102
+ for (int i = 0; i < numbers.size(); i++) {
103
+ int numberToFind = target - numbers[i];
104
+
105
+ //if numberToFind is found in map, return them
106
+ if (hash.find(numberToFind) != hash.end()) {
107
+ //+1 because indices are NOT zero based
108
+ result.push_back(hash[numberToFind] + 1);
109
+ result.push_back(i + 1);
110
+ return result;
111
+ }
112
+
113
+ //number was not found. Put it in the map.
114
+ hash[numbers[i]] = i;
115
+ }
116
+ return result;
117
+ }
0 commit comments