Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
*.swp

‎README.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /