Leetcode
class Solution:
def lengthOfLastWord(self, s: str) -> int:
spilt_list = s.split(" ")
spilt_list = list(filter(None,spilt_list))
if not spilt_list:
return 0
result = len(spilt_list[-1])
return result
網路解法
class Solution:
def lengthOfLastWord(self, s: str) -> int:
return len(s.rstrip().split(' ')[-1])
CH8 在線廣告實現 流程 每人先對本次進行自己的總結 問題討論 2022.02.16 問題討論
Mar 16, 2022題目 Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:
Oct 25, 2021Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1 Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2 Input: nums = [-7,-3,2,3,11]
Jun 7, 2021You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n. Example 1 Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
Jun 7, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up