请教:类似K99的private funding? (neuroscience)# Biology - 生物学
p*7
1 楼
You are given an array ' containing 0s and 1s. Find O(n) time and O(1) space
algorithm to find the maximum sub sequence which has equal number of 1s and
0s.
Examples
1) 10101010
The longest sub sequence that satisfies the problem is the input itself
2)1101000
The longest sub sequence that satisfies the problem is 110100
我想到一个办法,不知道是否正确
1.因为不知道1和0谁多,不好执行算法,所以先遍历一次统计下1和0数量,选少的那个
做标准
2.想统计10,想到的办法就是如果是1就+1,如果是0就-1,如果sum == 0就统计一次
长度,这样我们发现似乎对于上面例子这个办法可以work,不过如果上面的string反置
,这个办法就不work了,因为以为后面的0太多,而
algorithm to find the maximum sub sequence which has equal number of 1s and
0s.
Examples
1) 10101010
The longest sub sequence that satisfies the problem is the input itself
2)1101000
The longest sub sequence that satisfies the problem is 110100
我想到一个办法,不知道是否正确
1.因为不知道1和0谁多,不好执行算法,所以先遍历一次统计下1和0数量,选少的那个
做标准
2.想统计10,想到的办法就是如果是1就+1,如果是0就-1,如果sum == 0就统计一次
长度,这样我们发现似乎对于上面例子这个办法可以work,不过如果上面的string反置
,这个办法就不work了,因为以为后面的0太多,而