Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s - JAVA #leetcode

Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.

shift on s consists of moving the leftmost character of s to the rightmost position.


 class Solution {

public boolean rotateString(String value, String goal) {

int count=0;

if(value.equals(goal)){
count=count+1;
}


char arr[]=new char[value.length()];

for(int r=1;r<value.length();r++){

for(int i=0;i<value.length()-r;i++){
arr[i]=value.toCharArray()[i+r];

if(i<r){
arr[(value.length())-(r-i)]=value.toCharArray()[i];
}
for(int n=0;n<r;n++){
arr[(value.length())-(r-n)]=value.toCharArray()[n];
}

String string = new String(arr);



if(string.equals(goal)){
count=count+1;
break;
}
}

}

System.out.println("count "+count);
if(count>0){
return true;
}else{
return false;
}
}

}

Comments

Popular posts from this blog

Rest Assured

Sort (Bubble) - Java

Rotate the String from position - Java