Skip to content

Instantly share code, notes, and snippets.

@sangpt
Created March 16, 2017 16:11
Show Gist options
  • Save sangpt/a7e31f0868859d309f95f4f5493cbdc9 to your computer and use it in GitHub Desktop.
Save sangpt/a7e31f0868859d309f95f4f5493cbdc9 to your computer and use it in GitHub Desktop.
Cho trước 1 xâu. Viết function(tạm gọi là permAlone) liệt kê số các hoán vị của xâu sao cho không có 2 kí tự giống nhau đứng liền kề.
Ví dụ permAlone('aab') có các hoán vị (aab, aab, aba, aba, baa, baa) nhưng chỉ có 2 hoán vị đúng yêu cầu là (aba và aba).
Dữ liệu mẫu:
permAlone("aab") should return a number.
permAlone("aab") should return 2.
permAlone("aaa") should return 0.
permAlone("aabb") should return 8.
permAlone("abcdefa") should return 3600.
permAlone("abfdefa") should return 2640.
permAlone("zzzzzzzz") should return 0.
permAlone("a") should return 1.
permAlone("aaab") should return 0.
permAlone("aaabb") should return 12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment