Special String Again

  • + 1 comment

    For those who doesn't understand this line,

    for i in l: ans += (i[1] * (i[1] + 1)) / 2

    its from a formula n(n+1)/2 which give the sum of all term, like n = 5, 1+2+3+4+5 = 5(5+1)/2 = 15.

    Its used because if you have "aaaa" , you can have "a,a,a,a", "aa,aa,aa", "aaa,aaa" and "aaaa", we can see the partern of 4,3,2,1 groups, so in this case there's 15 groups!