Skip to content

Create Subarray Sum Equals K.md#18

Open
irohafternoon wants to merge 1 commit intomainfrom
560.-Subarray-Sum-Equals-K
Open

Create Subarray Sum Equals K.md#18
irohafternoon wants to merge 1 commit intomainfrom
560.-Subarray-Sum-Equals-K

Conversation

@irohafternoon
Copy link
Copy Markdown
Owner

This Problem
Subarray Sum Equals K
Next Problem
Number of Islands

for (int i = 0; i < nums.size(); i++) {
auto complement = k + cumulative_sum[i];
auto* indexes = &cumulative_sum_to_indexes[complement];
num_subarrays_with_sum_k += (*indexes).end() - std::upper_bound((*indexes).begin(), (*indexes).end(), i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご存じかもしれませんが、
1行の長さに関しても、Google C++ Style Guideに記載があります。

https://google.github.io/styleguide/cppguide.html#Line_Length

80 characters is the maximum.

A line may exceed 80 characters if it is

}
};
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

問題ないと思います。

for (int i = 0; i < nums.size(); i++) {
auto complement = k + cumulative_sum[i];
auto* indexes = &cumulative_sum_to_indexes[complement];
num_subarrays_with_sum_k += (*indexes).end() - std::upper_bound((*indexes).begin(), (*indexes).end(), i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*indexes).end() は、たぶん indexes->end() が使えますかね?

class Solution {
public:
int subarraySum(const std::vector<int>& nums, int k) {
std::map<int, std::vector<int>> cumulative_sum_to_indexes;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map<int, deque<int>> にしたら、頭から i 以下のものを削除していくだけでいったりしますかね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants