我对OCaml相当新,但是我正在研究这个项目,我不太了解不可变对象的概念,并且想知道我是否可以得到一些帮助,我是通过文本编辑器来做到这一点的并尝试过String.iter并爆炸,但仍然无法弄明白。
Description:
You are given a DNA sequence:
a string that contains only characters 'A', 'C', 'G', and 'T'.
Your task is to calculate the number of substrings of sequence,
in which each of the symbols appears the same number of times.
Example 1:
For sequence = "ACGTACGT", the output should be 6
All substrings of length 4 contain each symbol exactly once (+5),
and the whole sequence contains each symbol twice (+1).
Example 2:
For sequence = "AAACCGGTTT", the output should be 1
Only substring "AACCGGTT" satisfies the criterion above: it contains each symbol twice.
Input: String, a sequence that consists only of symbols 'A', 'C', 'G', and 'T'.
Length constraint: 0 < sequence.length < 100000.
输出:整数,每个符号出现次数的子串数。
编辑这就是我目前所拥有的:
let countA = ref 0
let countC = ref 0
let countG = ref 0
let countT = ref 0
let subStricount = ref 0
let countChar x =
match x with
'A'-> countA +1
|'C'-> countC +1
|'T'-> countT +1
|'G'-> countG +1
;;
let tempH = 0 in
let tempT = 3 in
let demoStri = "ACGTACGT" in
let striL = String.length demoStri in
for i = 0 to striL -1 do
for j = tempH to tempT do
countChar demoStri.[tempH];
done
done