Skip to content

Instantly share code, notes, and snippets.

View jyhjuzi's full-sized avatar

Yanhong Ju jyhjuzi

  • China
View GitHub Profile
import java.util.HashMap;
import java.util.Arrays;
public class Q1_3{
public static void main(String args[]){
String str1= "123gefrfd";
String str2= "231gerfdd";
System.out.println(isPermutation1(str1, str2));
}
public static boolean isPermutation2(String str1, String str2){
if(str1.length()!=str2.length())
public class Q1_4 {
public static void main(String args[]){
char[] test = {'a',' ','b',' ',' ','c',' ',' ',' ',' ',' ',' '};
System.out.println(process(test,6));
}
static String process(char[] array, int length){
int numberOfSpace = 0;
for(int i = 0; i<length; i++){
if(array[i] == ' ')
public class Q1_5{
public static void main(String args[]){
String test = "abbcdddedfff";
System.out.println(compress(test));
}
static String compress(String s){
StringBuffer ret = new StringBuffer();
char lastChar = s.charAt(0);
int count = 0;
public class Q1_6{
public static void main(String args[]){
int a[][] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}};
rotate(a);
for(int[] x :a){
for(int integer :x)
public class Q1_7 {
public static void main(String args[]) {
int a[][] = {
{0, 2, 0, 4},
{5, 6, 7, 8},
{9, 10, 0, 12},
{13, 14, 15, 16}};
process(a);
for(int[] x :a){
for(int integer :x)
public class Q1_8{
public static void main(String args[]){
String test1 = "test";
String test2 = "estt";
System.out.println(isRotation(test1, test2));
}
private static boolean isRotation(String s1, String s2){
if(s1.length() != s2.length())
return false;
String s= s2+s2;
import java.util.*;
class Node {
int content;
Node next;
Node(int x) {
content = x;
next = null;
}
public class Q2_2 {
public static void main(String args[]) {
Node test = arrayToLinkedList(new int[] { 1, 2, 3, 4, 5, 6 });
System.out.println(getKthEle(test, 1).value);
}
public static Node getKthEle(Node root, int k) {
Node pointer1 = root;
Node pointer2 = root;
for (int i = k; i > 0; i--) {
if (pointer2 == null)
public class Q2_3{
public static void main(String args[]){
Node test = arrayToLinkedList(new int[] {1,2,3,4,5}) ;
deleteElement(test.next.next.next);
System.out.println(compareLinkedList(test,
arrayToLinkedList(new int[] { 1,2,3,5})));
}
public class Q2_4 {
public static void main(String args[]) {
Node test = arrayToLinkedList(new int[] { 5, 2, 3, 4, 1, 2 });
Node output = sortLList(test, 3);
System.out.println(compareLinkedList(output, arrayToLinkedList(new int[] { 2,1,2,5,3,4 })));
}
public static Node sortLList(Node root, int val) {
Node head = root, cursor = root;
while (cursor.value < val && cursor.next != null) {