/images/avatar.png

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 解题思路: 累积和(使用数组) 首先使用一个cumulative数组,保存nums中从0开始到每个元素的累积求和。 然后,cumulative数组中两两数之间的差,对应nums中这两个位置之间的累积求和。

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 ')'.

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. 解题思路 直接按照进位处理即可。