Add solution 0058

This commit is contained in:
halfrost
2021-09-15 03:22:09 -07:00
parent 0d3b70571a
commit 71b771dc5d
5 changed files with 59 additions and 10 deletions

View File

@@ -126,16 +126,16 @@
| | Easy | Medium | Hard | Total |
|:--------:|:--------:|:--------:|:--------:|:--------:|
|Optimizing|34|40|31|105|
|Optimizing|33|40|31|104|
|Accepted|**284**|**414**|**124**|**822**|
|Total|517|1061|426|2004|
|Perfection Rate|88.0%|90.3%|75.0%|87.2%|
|Perfection Rate|88.4%|90.3%|75.0%|87.3%|
|Completion Rate|54.9%|39.0%|29.1%|41.0%|
|------------|----------------------------|----------------------------|----------------------------|----------------------------|
## 二. 目录
以下已经收录了 719 道题的题解,还有 11 道题在尝试优化到 beats 100%
以下已经收录了 720 道题的题解,还有 11 道题在尝试优化到 beats 100%
| No. | Title | Solution | Acceptance | Difficulty | Frequency |
|:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
@@ -196,7 +196,7 @@
|0055|Jump Game|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0055.Jump-Game)|36.2%|Medium||
|0056|Merge Intervals|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0056.Merge-Intervals)|42.8%|Medium||
|0057|Insert Interval|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0057.Insert-Interval)|36.4%|Medium||
|0058|Length of Last Word||34.4%|Easy||
|0058|Length of Last Word|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0058.Length-of-Last-Word)|34.4%|Easy||
|0059|Spiral Matrix II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0059.Spiral-Matrix-II)|59.8%|Medium||
|0060|Permutation Sequence|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0060.Permutation-Sequence)|40.7%|Hard||
|0061|Rotate List|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0061.Rotate-List)|32.8%|Medium||
@@ -365,7 +365,7 @@
|0224|Basic Calculator|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0224.Basic-Calculator)|39.3%|Hard||
|0225|Implement Stack using Queues|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0225.Implement-Stack-using-Queues)|49.8%|Easy||
|0226|Invert Binary Tree|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0226.Invert-Binary-Tree)|69.0%|Easy||
|0227|Basic Calculator II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0227.Basic-Calculator-II)|39.6%|Medium||
|0227|Basic Calculator II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0227.Basic-Calculator-II)|39.7%|Medium||
|0228|Summary Ranges|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0228.Summary-Ranges)|43.8%|Easy||
|0229|Majority Element II|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0229.Majority-Element-II)|40.3%|Medium||
|0230|Kth Smallest Element in a BST|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0230.Kth-Smallest-Element-in-a-BST)|64.6%|Medium||
@@ -1009,7 +1009,7 @@
|0868|Binary Gap||61.5%|Easy||
|0869|Reordered Power of 2|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0869.Reordered-Power-of-2)|61.2%|Medium||
|0870|Advantage Shuffle|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0870.Advantage-Shuffle)|50.9%|Medium||
|0871|Minimum Number of Refueling Stops||35.0%|Hard||
|0871|Minimum Number of Refueling Stops||35.1%|Hard||
|0872|Leaf-Similar Trees|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0872.Leaf-Similar-Trees)|64.7%|Easy||
|0873|Length of Longest Fibonacci Subsequence||48.5%|Medium||
|0874|Walking Robot Simulation|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0874.Walking-Robot-Simulation)|37.0%|Easy||
@@ -1182,7 +1182,7 @@
|1041|Robot Bounded In Circle||54.7%|Medium||
|1042|Flower Planting With No Adjacent||49.2%|Medium||
|1043|Partition Array for Maximum Sum||69.1%|Medium||
|1044|Longest Duplicate Substring||30.7%|Hard||
|1044|Longest Duplicate Substring||30.6%|Hard||
|1045|Customers Who Bought All Products||67.6%|Medium||
|1046|Last Stone Weight||62.6%|Easy||
|1047|Remove All Adjacent Duplicates In String|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1047.Remove-All-Adjacent-Duplicates-In-String)|71.3%|Easy||
@@ -2086,7 +2086,7 @@
|1945|Sum of Digits of String After Convert||62.0%|Easy||
|1946|Largest Number After Mutating Substring||33.1%|Medium||
|1947|Maximum Compatibility Score Sum||57.6%|Medium||
|1948|Delete Duplicate Folders in System||60.5%|Hard||
|1948|Delete Duplicate Folders in System||60.4%|Hard||
|1949|Strong Friendship||59.3%|Medium||
|1950|Maximum of Minimum Values in All Subarrays||50.9%|Medium||
|1951|All the Pairs With the Maximum Number of Common Followers||74.1%|Medium||

View File

@@ -78,5 +78,5 @@ func insert(intervals []Interval, newInterval Interval) []Interval {
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0056.Merge-Intervals/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0059.Spiral-Matrix-II/">下一页➡️</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0058.Length-of-Last-Word/">下一页➡️</a></p>
</div>

View File

@@ -0,0 +1,48 @@
# [58. Length of Last Word](https://leetcode-cn.com/problems/length-of-last-word/)
## 题目
Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string.
A word is a maximal substring consisting of non-space characters only.
Example 1:
```
Input: s = "Hello World"
Output: 5
Explanation: The last word is "World" with length 5.
```
Example 2:
```
Input: s = " fly me to the moon "
Output: 4
Explanation: The last word is "moon" with length 4.
```
Example 3:
```
Input: s = "luffy is still joyboy"
Output: 6
Explanation: The last word is "joyboy" with length 6.
```
## 题目大意
给你一个字符串 s由若干单词组成单词前后用一些空格字符隔开。返回字符串中最后一个单词的长度。
单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。
## 解题思路
- 先从后过滤掉空格找到单词尾部,再从尾部向前遍历,找到单词头部,最后两者相减,即为单词的长度
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0057.Insert-Interval/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0059.Spiral-Matrix-II/">下一页➡️</a></p>
</div>

View File

@@ -96,6 +96,6 @@ func generateMatrix(n int) [][]int {
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0057.Insert-Interval/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0058.Length-of-Last-Word/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0060.Permutation-Sequence/">下一页➡️</a></p>
</div>

View File

@@ -23,6 +23,7 @@ weight: 2
|0032|Longest Valid Parentheses|[Go]({{< relref "/ChapterFour/0001~0099/0032.Longest-Valid-Parentheses.md" >}})|Hard||||30.5%|
|0043|Multiply Strings|[Go]({{< relref "/ChapterFour/0001~0099/0043.Multiply-Strings.md" >}})|Medium||||35.9%|
|0049|Group Anagrams|[Go]({{< relref "/ChapterFour/0001~0099/0049.Group-Anagrams.md" >}})|Medium| O(n log n)| O(n)||61.8%|
|0058|Length of Last Word|[Go]({{< relref "/ChapterFour/0001~0099/0058.Length-of-Last-Word.md" >}})|Easy||||34.4%|
|0065|Valid Number|[Go]({{< relref "/ChapterFour/0001~0099/0065.Valid-Number.md" >}})|Hard||||17.0%|
|0067|Add Binary|[Go]({{< relref "/ChapterFour/0001~0099/0067.Add-Binary.md" >}})|Easy||||48.5%|
|0071|Simplify Path|[Go]({{< relref "/ChapterFour/0001~0099/0071.Simplify-Path.md" >}})|Medium| O(n)| O(n)||35.9%|