From edcdbd9e36e808291e0dd07b053e1b9fc36ba580 Mon Sep 17 00:00:00 2001 From: iamprayag <56070251+iamprayag@users.noreply.github.com> Date: Thu, 1 Oct 2020 13:54:55 +0530 Subject: [PATCH 1/4] Create leet_1525.py --- leet_1525.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 leet_1525.py diff --git a/leet_1525.py b/leet_1525.py new file mode 100644 index 0000000..287d33d --- /dev/null +++ b/leet_1525.py @@ -0,0 +1,16 @@ +import collections +class Solution: + def numSplits(self, s: str) -> int: + lc, rc = collections.Counter(), collections.Counter(s) + + res = 0 + for c in s: + lc[c] += 1 + rc[c] -=1 + + if rc[c]==0: + del rc[c] + + if len(lc) == len(rc): + res +=1 + return res From 4eec5f8644ff7a7856cc0dff03750234d4f05856 Mon Sep 17 00:00:00 2001 From: iamprayag <56070251+iamprayag@users.noreply.github.com> Date: Thu, 1 Oct 2020 13:58:58 +0530 Subject: [PATCH 2/4] Create leet_1310.py --- leet_1310.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 leet_1310.py diff --git a/leet_1310.py b/leet_1310.py new file mode 100644 index 0000000..3f1d1fb --- /dev/null +++ b/leet_1310.py @@ -0,0 +1,10 @@ +class Solution: + def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: + pref = [0] + for e in arr: + pref.append(e ^ pref[-1]) + ans = [] + for [l, r] in queries: + ans.append(pref[r+1] ^ pref[l]) + return ans + From 75a42c77c7cea3c1a047cca719d4cd21f3e3f2ca Mon Sep 17 00:00:00 2001 From: iamprayag <56070251+iamprayag@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:03:05 +0530 Subject: [PATCH 3/4] Create leet_338.cpp --- leet_338.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 leet_338.cpp diff --git a/leet_338.cpp b/leet_338.cpp new file mode 100644 index 0000000..79f1704 --- /dev/null +++ b/leet_338.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + vector countBits(int num) { + vector ans = {0, 1}; + int n=2; + int tot = 2; + int j=0; + if(num==0){ + vector ans = {0}; + return ans; + } + if(num==1){ + vector ans = {0, 1}; + return ans; + } + + while(tot != num+1){ + ans.push_back(ans[j]+1); + j+=1; + if(j==n){ + j=0; + n*=2; + } + tot+=1; + } + return ans; + } +}; From 2dded984c0597dd38504dce866d57d19f4182bbe Mon Sep 17 00:00:00 2001 From: iamprayag <56070251+iamprayag@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:16:00 +0530 Subject: [PATCH 4/4] Create leet_169.py --- leet_169.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 leet_169.py diff --git a/leet_169.py b/leet_169.py new file mode 100644 index 0000000..d353e02 --- /dev/null +++ b/leet_169.py @@ -0,0 +1,15 @@ +class Solution: + def majorityElement(self, nums: List[int]) -> int: + cur = None + cnt=0 + for e in nums: + if cnt == 0: + cnt=1 + cur=e + elif e == cur: + cnt += 1 + else: + cnt -= 1 + return cur + +