我编码的问题是我们要计算两个字符串中常见字符的数量.计数的主要部分是这样的
for(i=0; i < strlen(s1); i++) {
for(j = 0; j < strlen(s2); j++) {
if(s1[i] == s2[j]) {
count++;
s2[j] = '*';
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这与O(n ^ 2)逻辑一致.但是,我想不出比这更好的解决方案.任何人都可以用O(n)逻辑帮助我编码.
为什么最大数组与本地声明和全局声明不同?
我在一些博客中读到,在本地声明的情况下,我们可以声明的最大数组大小为10 ^ 6,在全局声明的情况下,在10 ^ 7到2*10 ^ 8之间.这是什么原因?
如何获得直线,文本和直线?
代码.这是我的HTML的jsfiddle.我使用内联属性使它们出现在一条直线上.但他们没有改变.
怎么做他们看起来像
---------------------- About Me ---------------------
(^^dotted line above should actually be single line.)
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
l=raw_input()
x=l.split(' ')
n=x[0]
w=x[1]
l=raw_input()
i=0
print n
while(i<n):
print "1 %d" %i
i=i+1
Run Code Online (Sandbox Code Playgroud)
和输入一样
6 6
1 2 3 4 5 3
Run Code Online (Sandbox Code Playgroud)
它给出了运行时错误.
虽然n被分配了6并i从0开始,但为什么在i = 6时没有结束?价值i增加超过n无限.