At first, I thought it should return an array of arrays of strings, in which each array of strings contains a group of anagrams. But in C++ default code just sets the return type as
vector<string> rather than vector< vector<string> >...
W
wyfyw
@wyfyw
4
Reputation
5
Posts
109
Profile views
0
Followers
0
Following
Posts made by wyfyw

RE: What will be the output of abc, cab, bca, dsa, asd, sad ?

Simple 2 pass Python code
Never take some guess for granted!
[1, 2, 2] is not 5, should be 4!Useq/Dseq stores one should have ?+1 candies since he/her has higher rating than left/right neighbor!
class Solution: # @param {integer[]} ratings # @return {integer} def candy(self, ratings): n = len(ratings) Useq = [0 for i in range(n)] for i in xrange(1, n): if ratings[i]>ratings[i1]: Useq[i] = Useq[i1]+1 Dseq = [0 for i in range(n)] for i in xrange(n2, 1, 1): #from i = n2, ... 1, 0 ## will not reach 1!! if ratings[i]>ratings[i+1]: Dseq[i] = Dseq[i+1]+1 candies = [max(Useq[i], Dseq[i])+1 for i in range(n)] return sum(candies)

RE: Share my C++ DP solution with O(kn) time O(k) space, 10ms
I use a
vector<int>
instead of yourint hold[k+1]
then I got a TLE...
Maybe they just don't turn on the O2 optimization...
After look at your code, I revised mine and got Accepted.
Thank you for your sharing! 
RE: Share my C++ DP solution with O(kn) time O(k) space, 10ms
Well, I think the transaction times should be <= half of the number of days(i.e. the prices). Since we need two days to finish a transaction~