Skip to main content

Algorithms: Tower of Hanoi


Có 3 chiếc cọc được đánh dấu lần lượt là A, B, C và n chiếc đĩa. Các đĩa này có kích thước khác nhau và mỗi đĩa đều có một lỗ ở giữa để cắm vào cọc. Ban đầu, các đĩa đều nằm ở cọc A, trong đó, đĩa nhỏ luôn nằm trên đĩa lớn hơn.

Solution:


Comments

Popular posts from this blog

Algorithm looks for the first character not repeating

Given a string  s , find and return the first instance of a non-repeating character in it. If there is no such character, return  '_' . Example For  s = "abacabad" , the output should be firstNotRepeatingCharacter(s) = 'c' . There are  2  non-repeating characters in the string:  'c'  and  'd' . Return  c  since it appears in the string first. For  s = "abacabaabacaba" , the output should be firstNotRepeatingCharacter(s) = '_' . There are no characters in this string that do not repeat. Input/Output [time limit] 500ms (cpp) [input] string s A string that contains only lowercase English letters. Guaranteed constraints: 1 ≤ s.length ≤ 10 5 . [output] char The first non-repeating character in  s , or  '_'  if there are no characters that do not repeat. My this solution: char firstNotRepeatingCharacter(std::string s) {     char temp = ' ';     for (int i...

Bài 3: Vị trí đặt Javascript trong HTML

Javascript rất linh hoạt để thêm vào một file HTML, tuy nhiên dưới đây là một số cách thường hay được sử dụng để chèn, thêm Javascript vào: Đặt trong cặp thẻ <head> ... </head> Đặt trong cặp thẻ <body> ... </body> Đặt trong cặp thẻ <head> ... </head> và <body> ... </body> Viết javascript trong một file .js bên ngoài và chèn vào cặp thẻ <head> ... </head> Bài 3: Vị trí đặt Javascript trong HTML