From 603a20df5ba02e781616be51971b0cafad0fa9d6 Mon Sep 17 00:00:00 2001 From: Snehagupta24 <73895587+Snehagupta24@users.noreply.github.com> Date: Tue, 11 Oct 2022 23:25:51 +0530 Subject: [PATCH] Tower_Of_Hanoi game please add the hacktoberfest accepted label --- TowerOfHanoi.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 TowerOfHanoi.java diff --git a/TowerOfHanoi.java b/TowerOfHanoi.java new file mode 100644 index 0000000..0099d28 --- /dev/null +++ b/TowerOfHanoi.java @@ -0,0 +1,20 @@ +class TowerOfHanoi{ + static int count = 0; + public static void toweOfHanoi(int n, String src,String help,String dest){ + if(n==1){ + //System.out.println("Transfer disk "+ n +" from "+ src +" to "+ dest); + count++; + return; + } + toweOfHanoi(n-1,src,dest,help); + //System.out.println("Transfer disk "+ n +" from "+ src +" to "+ dest); + toweOfHanoi(n-1,help,src,dest); + count++; + } + public static void main(String[] args) { + int n=100; + toweOfHanoi(n,"S","H","D"); + System.out.println(count); + } +} +//Time Complexity = O(2^n). \ No newline at end of file