# 796. Rotate String

796. Rotate String

```class Solution {
public boolean rotateString(String A, String B) {
return rotateString( A,  B , 0);
}

private boolean rotateString(String a, String b, int i) {
if( a.length() <=1 && b.length()  b.length()) return false;
if( a.equals(b)) return true;

return rotateString( a.substring(1)+a.charAt(0), b, i+1);
}
}```

# 784. Letter Case Permutation

784. Letter Case Permutation

```class Solution {
public static List letterCasePermutation(String S) {
List list = new ArrayList();
letterCase(S, 0, list);
return list;
}

private static void letterCase(String s, int i, List list) {
if (i == s.length()) {
return;
}
char a = s.charAt(i);
if (Character.isDigit(a)) {
letterCase(s, i + 1, list);
} else {
if (Character.isUpperCase(a)) {
letterCase(s.substring(0, i) + Character.toLowerCase(a) + s.substring(i + 1), i + 1, list);
letterCase(s.substring(0, i) + a + s.substring(i + 1), i + 1, list);
} else if (Character.isLowerCase(a)) {
letterCase(s.substring(0, i) + Character.toUpperCase(a) + s.substring(i + 1), i + 1, list);
letterCase(s.substring(0, i) + a + s.substring(i + 1), i + 1, list);
}
}
}
}
```

# Java Primality Test

Java Primality Test

```import java.util.*;
import java.math.*;

public class Solution {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger n = in.nextBigInteger();
in.close();

if (!n.equals(new BigInteger("1")) && n.isProbablePrime(1))
System.out.println("prime");
else
System.out.println("not prime");

}
}

```

# 762. Prime Number of Set Bits in Binary Representation

762. Prime Number of Set Bits in Binary Representation

```class Solution {
boolean isPrime(int n) {
if( n ==1 ) return false;
for (int i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}

public int countPrimeSetBits(int L, int R) {
int count = 0;
for (int i = L; i <= R; i++) {
String binary = Integer.toBinaryString(i);
int setBits = 0;
for (int j = 0; j < binary.length(); j++)
if (binary.charAt(j) == '1')
setBits++;
if (isPrime(setBits))
count++;
}
return count;
}
}```

# Android / Iphone disk clean up

I saved 500MB on my phone using Files Go! Can you save more? Try the app at g.co/filesgo. #filesgo

# 693. Binary Number with Alternating Bits

693. Binary Number with Alternating Bits

```class Solution {
public boolean hasAlternatingBits(int n) {
String binary = Integer.toBinaryString(n);

for (int i = 1; i < binary.length(); i++) {
if (binary.charAt(i) == binary.charAt(i - 1))
return false;
}

return true;
}
}```

# 566. Reshape the Matrix

566. Reshape the Matrix

```class Solution {
public int[][] matrixReshape(int[][] nums, int r, int c) {
if (nums.length * nums[0].length != r * c)
return nums;
int[][] out = new int[r][c];

boolean[][] visited = new boolean[r][c];

for (int i = 0; i < nums.length; i++)
for (int j = 0; j < nums[i].length; j++) {
searchEmptyPlace: {
for (int a = 0; a < out.length; a++)
for (int b = 0; b < out[a].length; b++)
if (!visited[a][b]) {
out[a][b] = nums[i][j];
visited[a][b] = true;
break searchEmptyPlace;
}
}
}

return out;
}
}```