File tree 5 files changed +83
-1
lines changed
ProgrammingSkills/1.Simulation
5 files changed +83
-1
lines changed Original file line number Diff line number Diff line change @@ -46,3 +46,26 @@ var romanToInt = function(s) {
46
46
return result ;
47
47
} , 0 ) ;
48
48
} ;
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
+ // };
Original file line number Diff line number Diff line change 21
21
var lengthOfLastWord = function ( s ) {
22
22
return s . trim ( ) . split ( / \s + / ) . pop ( ) . length ;
23
23
} ;
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
+ // };
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change @@ -215,4 +215,9 @@ Better order to solve problems
215
215
389 . Find the Difference
216
216
28 . Find the Index of the First Occurrence in a String
217
217
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
You can’t perform that action at this time.
0 commit comments