diff --git a/DiffiRecursion.java b/DiffiRecursion.java new file mode 100644 index 0000000000..718d186f81 --- /dev/null +++ b/DiffiRecursion.java @@ -0,0 +1,131 @@ +public class DiffiRecursion { + public static int first =-1; + public static int last =-1; + public static boolean [] map = new boolean[26]; + + +// public static void towerOfHanoi(int n, String src,String Helper,String Dest) +// {// base case +// if(n==1) +// { +// System.out.println("transfer disk "+ n+" "+ "from"+" "+src +" "+"to"+" "+Dest); +// return; +// } + +// towerOfHanoi(n-1, src, Dest, Helper); +// System.err.println("transfer disk "+ n+" "+ "from"+" "+src +" "+"to"+" "+Dest); +// towerOfHanoi(n-1, Helper, src, Dest); + + +// } + +// public static void RevStr(String str,int inx) +// {//time complexity = O(n) +// if(inx==0) +// { +// System.out.println(str.charAt(inx)); +// return; +// } +// System.out.println(str.charAt(inx)); +// RevStr(str, inx-1); +// } + + public static void FindOcurr(String str, int idx, char element) + { if(idx==str.length()) + { + System.out.println(first); + System.out.println(last); + return; + } + + char Currchar = str.charAt(idx); + if(Currchar == element) + { + if(first ==-1) + { + first = idx; + } + else{ + last= idx; + } + } + FindOcurr(str, idx+1, element); + + + } + + // public static boolean SortedArray(int arr[],int idx) + // { //we are chcking aray is sorted or not + // //time complexity = O(n) + // if(idx==arr.length-1) + // { + // return true; + // } + // if(arr[idx]