Find only one occurrence of the number of times in an array where all the other numbers appear K, found only once in an array of k in other numbers

Source: Internet
Author: User

Find only one occurrence of the number of public class getnumone{//Get only one occurrence of the number of public static int onecenum (Int[]arr,int k) in an array where the other numbers appear K
       	  {int[]e0=new int[32];
       	  for (int i=0;i<arr.length;i++) {setcurexc (e0,arr[i],k);
       	  Converts the number of//k into decimal int cur=getnumfromknum (E0,K);
          System.out.println ();

       return cur; //Get the intermediate steps to get only one occurrence of the K-number public static void Setcurexc (Int[]e0,int value,int k) {int[]res=g
       	  Etknumfromnum (VALUE,K);
       	  for (int i=0;i<e0.length;i++) {e0[i]= (e0[i]+res[i])%k;
       Converts a decimal integer to a K-binary number public static int[] Getknumfromnum (int value,int k)
       	  {int[]res=new int[32];
       	  int index=0;
       	  	  while (value!=0) {res[index++]=value%k;
       	  value=value/k;
       return res;
       A decimal integer that converts the number of K intopublic static int Getnumfromknum (Int[]e0,int k) {int res=0;
            for (int i=e0.length-1;i>=0;i--) {res=res*k+e0[i];
       return res;
	  	public static void Main (String []args) {//system.out.println ("Hello");
	  	int[]arr={1,1,1,2,2,2,3}; int k=3;
 
	  K indicates the number of times the other number appears System.out.println (Onecenum (arr,k));  }
}


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.