import java.util.*; public class Solution { /** * * @param n long长整型 * @return int整型 */ public int Numberofoperations (long n) { // write code here if(n==1||n==2)return -1; int count=0; ArrayList list=new ArrayList(); list.add(n); while(n!=0){ if(n%2==0){ n=n/2; if(list.contains(n))break; count++; list.add(n); }else{ n=n-3; if(list.contains(n))break; count++; list.add(n); } } list.clear(); if (n==0){ return count; }else{ return -1; } } }
全部评论
(0) 回帖