标签:int code public bsp span return ret bool lse
class Solution { public: bool checkSubarraySum(vector<int>& nums, int k) { unordered_map<int,int> m; // 从头元素开始的sum,取模为key的index。 m[0] = -1; int _sum = 0; for (int i = 0; i < nums.size(); i++) { _sum += nums[i]; if (k != 0) _sum = _sum % k; if (m.find(_sum) != m.end()) { if (m[_sum]+1 < i) return true; } else { m[_sum] = i; } } return false; } };
标签:int code public bsp span return ret bool lse
原文地址:https://www.cnblogs.com/JTechRoad/p/9108501.html