问题15.在二进制序列中找到1的最长序列。
解决方案统计
Problem Comments
-
8条评论
Nice and useful !
好一个
Nice one, didn't think it was possible to do in one line initially...
同意,有用
好问题。应该考虑解决
不错的解决方案万博 尤文图斯
interesting
很大的问题
解决方案评论
-
2条评论
noice
cool
-
1条评论
function y = lengthOnes(x)
y = double(x == '1');
l = numel(y);
a = tril(一个(l,l));
C = mat2cell(A,ones(1,L),L);
D = cellfun(@(c) conv(c,y),C,"UniformOutput",false);
e = cellfun(@(c)sum(c),c);
f = cellfun(@(c)max(c),d);
r = max(e(f == e));
if(isempty(R))
y = 0;
else
y = r;
结尾
结尾
-
2条评论
function y = lengthOnes(x)
cnt=0;
a = [];
l = strlength(x);
for i=1:L
if x(i)=='1'
cnt=cnt+1;
else
cnt=0;
结尾
a(i)= cnt;
结尾
[y,index]=max(a);
结尾
Excellent work man :)
-
1条评论
They are characters not doubles!
-
3条评论
function y = lengthOnes(x)
a = [];
idx = [1,find(x=='0') + 1,length(x)+2];
le = length(idx);
a(1:le-1)= idx(2:le)-idx(1:le-1)-1;
y = max(a);
结尾
实际上不需要言论
Cool
-
2条评论
解决d on iPhone
@Martin在诺基亚X2-02上解决了
-
1条评论
Any suggestions on how to improve more ?
-
1条评论
如何改进代码?
-
1条评论
a = regexp(x,'0+','split')
a=a{max(length(a))}
y =长度(a)
With this code, every test passes except 4th one. Why is it so?
-
1条评论
有什么方法可以改善该算法?
when y is empty vector, max(y) is not returning zero which is making my code complicated
-
3条评论
它在我的MATLAB程序中运行良好。
您的MATLAB需要多少时间?科迪有50秒的限制
Aditya Jain
Do you have a source for that time limit info?
-
1条评论
probably the most inefficient code ever written :)
-
3条评论
-
1条评论
I know it's not very efficient, but I sort of liked an idea behind this loop. Hence shared.
-
1条评论
Great solution that's easy to understand adn translatable to future use.
-
1条评论
非常不熟悉“ Regexp”功能会导致非常愚蠢的代码...
-
1条评论
hmmmmm.... ;-) nice
-
2条评论
-
1条评论
最后,在科迪中正确使用regexp
-
1条评论
您能解释您的代码吗?
Problem Recent Solvers4584
Suggested Problems
3463 Solvers
What is the next step in Conway's Life?
1023 Solvers
1743 Solvers
What is the distance from point P(x,y) to the line Ax + By + C = 0?
319求解器
519 Solvers