/images/avatar.png

lc238. Product of Array Except Self

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

You must write an algorithm that runs in O(n) time and without using the division operation.

Example 1:

1
2
Input: nums = [1,2,3,4]
Output: [24,12,8,6]

Example 2:

lc415. Add Strings

Given two non-negative integers, num1 and num2 represented as string, return the sum of num1and num2 as a string.

You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly.

Example 1:

1
2
Input: num1 = "11", num2 = "123"
Output: "134"

Example 2:

1
2
Input: num1 = "456", num2 = "77"
Output: "533"

Example 3:

lc560. Subarray Sum Equals K

Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.

Example 1:

1
2
Input: nums = [1,1,1], k = 2
Output: 2

Example 2:

1
2
Input: nums = [1,2,3], k = 3
Output: 2

Constraints:

  • 1 <= nums.length <= 2 * 104
  • -1000 <= nums[i] <= 1000
  • -107 <= k <= 107
解题思路:

累积和(使用数组)

lc301. Remove Invalid Parentheses

Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.

Return all the possible results. You may return the answer in any order.

Example 1:

1
2
Input: s = "()())()"
Output: ["(())()","()()()"]

Example 2:

1
2
Input: s = "(a)())()"
Output: ["(a())()","(a)()()"]

Example 3:

1
2
Input: s = ")("
Output: [""]

Constraints:

  • 1 <= s.length <= 25
  • s consists of lowercase English letters and parentheses '(' and ')'.
  • There will be at most 20 parentheses in s.

难点:本题和1249. 移除无效的括号非常相似,但是这里最难的点是如何找到所有的可能解。

lc67. Add Binary

Given two binary strings a and b, return their sum as a binary string.

Example 1:

1
2
Input: a = "11", b = "1"
Output: "100"

Example 2:

1
2
Input: a = "1010", b = "1011"
Output: "10101"

Constraints:

  • 1 <= a.length, b.length <= 104
  • a and b consist only of '0' or '1' characters.
  • Each string does not contain leading zeros except for the zero itself.
解题思路

直接按照进位处理即可。

lc273. Integer to English Words

Convert a non-negative integer num to its English words representation.

Example 1:

1
2
Input: num = 123
Output: "One Hundred Twenty Three"

Example 2:

1
2
Input: num = 12345
Output: "Twelve Thousand Three Hundred Forty Five"

Example 3:

1
2
Input: num = 1234567
Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"

Constraints:

  • 0 <= num <= 2^31 - 1
解题思路:

根据数字长度分成不同的翻译位: