From 7708267650a8c504a0a4addfa62708ab8504c992 Mon Sep 17 00:00:00 2001 From: chayan das Date: Sun, 16 Nov 2025 19:42:16 +0530 Subject: [PATCH] Create 1513. Number of Substrings With Only 1s --- 1513. Number of Substrings With Only 1s | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 1513. Number of Substrings With Only 1s diff --git a/1513. Number of Substrings With Only 1s b/1513. Number of Substrings With Only 1s new file mode 100644 index 0000000..daaa708 --- /dev/null +++ b/1513. Number of Substrings With Only 1s @@ -0,0 +1,20 @@ +class Solution { +public: + static const int M = 1000000007; + + int numSub(string s) { + long long ans = 0; + long long count1 = 0; + + for (char ch : s) { + if (ch == '1') { + count1++; + ans = (ans + count1) % M; + } else { + count1 = 0; + } + } + + return (int)ans; + } +};