Skip to content

Commit 793c84d

Browse files
committed
upd: Regular Expression Matching & Length of Last Word
1 parent ab2a0ff commit 793c84d

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
*.swp

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ LeetCode JavaScript Solution
1414
| Median of Two Sorted Arrays | Hard | 2017-10-13 |
1515
| Longest Palindromic Substring | Medium | 2018-01-19 |
1616
| Reverse Integer | Easy | 2018-01-19 |
17+
| Regular Expression Matching | Hard | 2018-03-09 |

src/lengthOfLastWord.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
* @return {number}
44
*/
55
var lengthOfLastWord = function(s) {
6-
var temp = s.replace(/\ +/g, ' ').split(' ');
7-
return (temp[temp.length - 1] && temp[temp.length -1].length) || (temp[temp.length - 2] && temp[temp.length -2].length) || 0;
6+
var temp = s.replace(/\ +/g, ' ').trim().split(' ');
7+
return temp[temp.length - 1].length;
88
};

0 commit comments

Comments
 (0)