1513. Number of Substrings With Only 1s

Share
1513. Number of Substrings With Only 1s
Photo by NASA / Unsplash

Leetcode Daily again, this problem was pretty strightforward this time as well.

Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 10^(9) + 7.

A simple and short description, nothing too fancy just count the substrings that only have characters 1 with the given string.

Though the main issue I had was READING the problem.

First time I miss was:

with all characters 1

I thought it needs to include 1s, so my math was pretty off from that and it took a bit for me to read

also I mess up on not reading the last part correctly, I thought it was modulo of 10^(9) * 7

Here is the solution code very straight forward:

class Solution:
    def numSub(self, s: str) -> int:
        ans = 0
        count = 0
        MOD = 7 + (10 ** 9)
        for i in range(len(s)):
            c = s[i]
            if c == '1':
                count = count + 1
                ans = (ans + count) % MOD
            else:
                count = 0
        return ans

Read more

蜡笔小新《大人帝国的反击》Nostalgia, and Why I Almost Built DeepSeek

蜡笔小新《大人帝国的反击》Nostalgia, and Why I Almost Built DeepSeek

Thanks for Chatgpt voice for fixing my awful chinese 碎碎念 grammar 所以这个是中文的博客,很久没写了,所以想要看一下怎么写。 大概有三四年没写了吧,有时候最近越来越少用中文了,感觉可以再加努力一下。 所以这是想说一下以前看的小动画片吧,这边有蜡笔小新:大人帝国的反击,然后下面连了一个视频,YouTube的视频(油管的视频),可以看一下,是比较详细的介绍吧,宣传一下。如果论知名度的话,看字幕的话大概知道它。 如果单说这部电影的话,我个人觉得它是我小时候看过最好的动画电影之一。《蜡笔小新》系列其实几乎每年都会出一部剧场版,但我大概从 2016 年左右开始就慢慢不看了,主要是因为太忙了,然后就是基本看不到 这次重新想起来,是因为最近又开始偶尔看看《蜡笔小新》,当作“下饭番”还挺轻松的。虽然不算特别认真地看,但还是会被一些情节触动。 那我对蜡笔小新《大人帝国的反击》具体的印象就是,大概大人全部走掉,然后小孩子的天堂吧。

By Tomato