如果我有两个角色(a, b
)和长度为三(aaa, aab ...
),我如何计算我可以用它组成多少个唯一的字符串(以及数学方法是什么)?
它是否正确?
val = 1, amountCharacters = 2, length = 3;
for (i = 1; i <= length; ++i) { val = amountCharacters*val; uniqueStrings = val }
此示例返回正确的 8。如果我尝试更高的东西,比如amountCharacters = 10
它返回 1000。它仍然正确吗?
If you have n different characters and the length is k, there are exactlty nk possible strings you can form. Each character independently of the rest can be one of n different options and there are k total choices to make. Your code is correct.
对于 2 个可能的字符和 10 个字母,正好有 1024 个可能的字符串。
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)