Skip to content

Commit c71e97f

Browse files
BarklimBarklim
Barklim
authored and
Barklim
committed
simulation topics
1 parent 058d082 commit c71e97f

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

0013-roman-to-integer.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,26 @@ var romanToInt = function(s) {
4646
return result;
4747
}, 0);
4848
};
49+
50+
// var romanToInt = function(s) {
51+
// let res = 0;
52+
// const roman = {
53+
// 'I': 1,
54+
// 'V': 5,
55+
// 'X': 10,
56+
// 'L': 50,
57+
// 'C': 100,
58+
// 'D': 500,
59+
// 'M': 1000
60+
// };
61+
62+
// for (let i = 0; i < s.length - 1; i++) {
63+
// if (roman[s[i]] < roman[s[i + 1]]) {
64+
// res -= roman[s[i]];
65+
// } else {
66+
// res += roman[s[i]];
67+
// }
68+
// }
69+
70+
// return res + roman[s[s.length - 1]];
71+
// };

0058-length-of-last-word.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@
2121
var lengthOfLastWord = function(s) {
2222
return s.trim().split(/\s+/).pop().length;
2323
};
24+
25+
// var lengthOfLastWord = function(s) {
26+
// let end = s.length - 1;
27+
28+
// while (end >= 0 && s[end] === ' ') {
29+
// end--;
30+
// }
31+
32+
// let start = end;
33+
// while (start >= 0 && s[start] !== ' ') {
34+
// start--;
35+
// }
36+
37+
// return end - start;
38+
// };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var lengthOfLastWord = function(s) {
6+
7+
};
8+
9+
const example1 = lengthOfLastWord("Hello World"); // 5
10+
const example2 = lengthOfLastWord(" fly me to the moon "); // 4
11+
const example3 = lengthOfLastWord("luffy is still joyboy"); // 6
12+
13+
console.log(example1);
14+
console.log(example2);
15+
console.log(example3);
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 {string}
4+
*/
5+
var toLowerCase = function(s) {
6+
let result = '';
7+
for (let i = 0; i < s.length; i++) {
8+
const ascii = s.charCodeAt(i);
9+
if (ascii >= 65 && ascii <= 90) {
10+
result += String.fromCharCode(ascii + 32);
11+
} else {
12+
result += s.charAt(i);
13+
}
14+
}
15+
return result;
16+
};
17+
18+
const example1 = lengthOfLastWord("Hello World"); // 5
19+
const example2 = lengthOfLastWord(" fly me to the moon "); // 4
20+
const example3 = lengthOfLastWord("luffy is still joyboy"); // 6
21+
22+
console.log(example1);
23+
console.log(example2);
24+
console.log(example3);

example/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,9 @@ Better order to solve problems
215215
389. Find the Difference
216216
28. Find the Index of the First Occurrence in a String
217217
459. Repeated Substring Pattern
218-
66. Plus One
218+
66. Plus One
219+
220+
### [0.Basic](https://github.com/Barklim/leetcode-javascript/tree/master/example/ProgrammingSkills/1.Simulation)
221+
222+
58. Length of Last Word
223+
1041. Robot Bounded In Circle

0 commit comments

Comments
 (0)