Algorithm-LeetCode_Plus_One

Plus One

English:

Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

You may assume the integer does not contain any leading zero, except the number 0 itself.

Example 1:

Example 2:

中文:

给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。

最高位数字存放在数组的首位, 数组中每个元素只存储一个数字。

你可以假设除了整数 0 之外,这个整数不会以零开头。

示例 1:

示例 2:

Answer(Use Time:52ms; Language: Python3):

Best Answer(Use Time:36ms; Language: Python3):

Algorithm-LeetCode_Length_Of_Last_Word

Length Of Last Word

English:

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.

If the last word does not exist, return 0.

Note: A word is defined as a character sequence consists of non-space characters only.

Example:

中文:

给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。

如果不存在最后一个单词,请返回 0 。

说明:一个单词是指由字母组成,但不包含任何空格的字符串。

示例:

Answer(Use Time:44ms; Language: Python3):

Best Answer(Use Time:36ms; Language: Python3):

Algorithm-LeetCode_Maximum_Subarray

Maximum Subarray

English:

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Example:

Follow up:

If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

中文:

给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。

示例:

进阶:

如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。

Answer(Use Time:56ms; Language: Python3):

Best Answer(Use Time:44ms; Language: Python3):

Algorithm-LeetCode_Count_And_Say

Count And Say

English:

The count-and-say sequence is the sequence of integers with the first five terms as following:

1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.

Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence.

Note: Each term of the sequence of integers will be represented as a string.

Example 1:

Example 2:

中文:

报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数。其前五项如下:

1 被读作  "one 1"  ("一个一") , 即 11
11 被读作 "two 1s" ("两个一"), 即 21
21 被读作 "one 2",  “one 1" ("一个二" ,  "一个一") , 即 1211

给定一个正整数 n(1 ≤ n ≤ 30),输出报数序列的第 n 项。

注意:整数顺序将表示为一个字符串。

示例 1:

示例 2:

Answer(Use Time: 44ms; Language: Python3):

Best Answer(Use Time:36ms; Language: Python3):

Algorithm-LeetCode_Search_Insert_Position

Search Insert Position

English:

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

Example 1:

Example 2:

Example 3:

Example 4:

中文:

给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。

你可以假设数组中无重复元素。

示例 1:

示例 2:

示例 3:

示例 4:

Answer(Use Time:44ms; Language: Python3):

Best Answer(Use Time:36ms; Language: Python3):