Skip to content

Commit 523763d

Browse files
author
lewis617
committed
Add numbers to LeetCode algorithms
1 parent 7234983 commit 523763d

22 files changed

+56
-10
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var lengthOfLongestSubstring = function (s) {
6+
if (s.length === 0) {
7+
return 0;
8+
}
9+
10+
var map = {},
11+
max = 0,
12+
l = 0;
13+
14+
for (var r = 0; r < s.length; ++r) {
15+
if (s.charAt(r) in map) {
16+
l = Math.max(l, map[s.charAt(r)] + 1);
17+
}
18+
map[s.charAt(r)] = r;
19+
max = Math.max(max, r - l + 1);
20+
}
21+
return max;
22+
};
23+
24+
module.exports = lengthOfLongestSubstring;

LeetCode/008-myAtoi.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @param {string} str
3+
* @return {number}
4+
*/
5+
var myAtoi = function(str) {
6+
return Math.max(Math.min(parseInt(str) || 0, 2147483647), -2147483648);
7+
};
8+
9+
module.exports = myAtoi;
File renamed without changes.
File renamed without changes.
File renamed without changes.

LeetCode/rob2.js renamed to LeetCode/213-rob2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @return {number}
44
*/
55
var rob = function(nums) {
6-
var rob1 = require('./rob1');
6+
var rob1 = require('./198-rob1');
77

88
if (nums.length === 1) {
99
return nums[0];
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)