如何去建设一个企业网站利用php做网站
如何去建设一个企业网站,利用php做网站,设计和建设一个网站要多少钱,南昌网站建设开发公司Problem: 930. Binary Subarrays With Sum 和相同的二元子数组 前缀和#xff0c;哈希表记录每个和所在的索引i#xff0c;对goal0分开讨论的#xff0c;使用前缀和- goal#xff0c;拿到s prefixSum[i1] - goal;#xff0c;数可能的子数组个数#xff0c;并累加
Code …Problem: 930. Binary Subarrays With Sum 和相同的二元子数组前缀和哈希表记录每个和所在的索引i对goal0分开讨论的使用前缀和- goal拿到s prefixSum[i1] - goal;数可能的子数组个数并累加Codeclass Solution { public: int numSubarraysWithSum(vectorint nums, int goal) { vectorint prefixSum {0}; int n nums.size(), s 0; unordered_mapint, vectorint ump; ump[0] {-1}; for(int i 0; i n; i) { s nums[i]; prefixSum.push_back(s); ump[s].push_back(i); } int ans 0, l, r; for(int i 0; i n; i) { s prefixSum[i1] - goal; if(ump.count(s) ! 0) { if(goal0) { ans i - ump[s][0]; } else { r l ump[s].back(); while(l 0 nums[l]0) l--; ans r - l 1; } } } return ans; } };