To determine whether two strings are variant words __boolean

Source: Internet
Author: User

Determine whether two strings are variants of each other the public
class bianstring{
	//judgment string is a variant of the word public
	static Boolean isdeformation (String str1, String str2)
	{

		if (str1==null| | str2==null| | Str1.length ()!=str2.length ())
		{return
			false;
		}
		Char[]ch1=str1.tochararray ();
		Char[]ch2=str2.tochararray ();
		Int[]map=new int[256]; The number of times the occurrence of each character is stored for
		(int i=0;i<ch1.length;i++)
		{
			map[ch1[i]]++
		}
		for (int i=0;i<ch2.length;i++)
		{
			if (map[ch2[i]]--==0) {return
				false;
			}
		}
		return true;

	}
	public static void Main (String[]args)
	{
      String str1= "123";
      String str2= "231";

      String str3= "123";
      String str4= "1223";
      System.out.println (Isdeformation (STR1,STR2));
      System.out.println (Isdeformation (STR3,STR4));
	}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.