¿Esta es tu empresa?
Questions about anagrams and circular linked list
Anónimo
Below is the code for String Anagrams: I guess this should be the fastest one: //Assumption: The case doesn't matter. //IF it does, just remove the toLowerCase() from both strings. import java.util.Scanner; public class CheckStringAnagram { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please enter first String"); String a = scan.next(); System.out.println("Please enter second String"); String b = scan.next(); System.out.println("Matched " + matchStrings(a.toLowerCase().toCharArray(), b.toLowerCase().toCharArray())); scan.close(); } //Assumed: the length of both strings is same. public static boolean matchStrings(char[] A, char[] B) { if (A.length != B.length) return false; int end = A.length - 1; buildMaxHeap(A, end); buildMaxHeap(B, end); for (int i = 0;i = 0) { int left = (2 * i) + 1; int right = (2 * i) + 2; if ( right = A[left] ) { swap(A, i, right); } else if (left = A[left] ) { swap(A, i, right); heapify(A, right, end); } else if (left <= end && A[i] < A[left]) { swap(A, i, left); heapify(A, left, end); } else return; } public static void swap(char[] A, int i, int j) { char temp = A[i]; A[i] = A[j]; A[j] = temp; } }