Write a function anagram(s, t)
to determine if the two strings are in reverse alphabetical order.
Give s= "abcd"
, t= "dcab"
, returntrue
Python: First sort after comparison
Class solution: "" " @param s:the First string @param b:the Second string @return True or False " ""
def Anagram (self, S, T): # Write your code here s = "". Join ((Lambda x: (X.sort (), x) [1]) (list (s))) t = "". Joi N ((Lambda y: (Y.sort (), y) [1]) (list (t))) if s = = = T: return True else: return False
C + +: using hash ideas
Class Solution {public: /** * @param s:the First string * @param b:the Second string * @return true or F Alse * /bool Anagram (string s, String t) { //write your code here if (s.length ()! = T.length ()) { ret Urn false; } int length = S.length (); int a[128]={0}; int b[128]={0}; for (int i = 0; i < length; i++) { int a1 = s[i]; int b1 = t[i]; a[a1]++; b[b1]++; } for (int i =0; i <; i++) { if (a[i]! = B[i]) return false; } return true; }};
Two strings are conjugation words