1. 如果字符串s中的字符循環移動任意位置之后能夠得到另一字符串t,那么s就被稱為t的回環變位。例如,ACTGACG 就是 TGACGAC 的一個回環變位,反之亦然。判定這個條件在基因組序列中的研究是十分重要的。編寫一個算法檢查兩個給定的字符串s和t是否互為回環變位。
答:public static boolean isCircularRotation(String s, String t) { return s.length() == t.length() && (t + t).contains(s); }。
2. 累加器的方差計算,長度為N,新輸入數據為x
public void addDataValue(double x){ N++; s = s + 1.0 * (N-1) / N * (x - m ) * (x - m); m = m + (x - m) / N;}return m;return s / (N-1);return Math.sqrt(this.var());
新聞熱點
疑難解答