Hackerrank – Problem Statement A description of the problem can be found on Hackerrank. Solution I explain my solution with following examples: Example 1234 I start with a beginning of a string, which would be one digit number – 1 and try to examine a rest of the given string 234. Next...
昵称:Tonix 园龄:14年11个月 粉丝:2 关注:2 +加关注 Should be "Medium" or even "Easy".. Just with a little Greedy. classSolution {public:/** * @param S: A list of integers * @return: An integer*/inttriangleCount(vector<int> &S) {intn =S.size();if(n <3)return0; sort(S....
And an alternative solution is to use MergeSort to count, also interesting: https://leetcode.com/discuss/79154/short-%26-simple-o-n-log-n
storage[num] -=1 This uses a similar solution as yours, mylstisnums. However, I aimed at obtainingO(1)O(1)in bothaddanddel. I can't complete the problem. The way Python programmers that solved this use[0] * (2 ** 16)and binary logic I don't know. Which make all the function...
classSolution {///Fenwick Tree//vector<int>ft;voidupdate(inti,intx) {if((i +1) > ft.size())return;for(; i < ft.size(); i += (i & -i)) ft[i]+=x; }intquery(inti) { i= min(i,int(ft.size() -1));ints =0;for(; i >0; i -= (i & -i)) s+=ft[i];returns...