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 + 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 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 + + 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; + } +};