Skip to content

Latest commit

 

History

History
76 lines (54 loc) · 1.3 KB

[0930] 和相同的二元子数组.md

File metadata and controls

76 lines (54 loc) · 1.3 KB
title tags categories author comments updated permalink mathjax top description date
[0930] 和相同的二元子数组
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:15:30 -0800

题目描述

在由若干 0 和 1  组成的数组 A 中,有多少个和为 S 的非空子数组。

 

示例:

输入:A = [1,0,1,0,1], S = 2
输出:4
解释:
如下面黑体所示,有 4 个满足题目要求的子数组:
[1,0,1,0,1]
[1,0,1,0,1]
[1,0,1,0,1]
[1,0,1,0,1]

 

提示:

  1. A.length <= 30000
  2. 0 <= S <= A.length
  3. A[i] 为 0 或 1
Related Topics
  • 哈希表
  • 双指针
  • 题目代码

    class Solution {
    public:
        int numSubarraysWithSum(vector<int>& A, int S) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三