Skip to content

Instantly share code, notes, and snippets.

@herrryan
herrryan / WordPattern.java
Created December 8, 2016 14:23
Solution to Word Pattern Leetcode 290
public class Solution {
public boolean wordPattern(String pattern, String str) {
if (pattern == null || str == null) return false;
String[] words = str.split(" ");
if (pattern.length() != words.length) return false;
HashMap<Character, String> map = new HashMap<Character, String>();
for (int i = 0; i < pattern.length(); i++){
char c = pattern.charAt(i);
String s = words[i];
@herrryan
herrryan / RotateAnArray.java
Last active November 28, 2016 14:13
Solution for rotating array, link https://leetcode.com/problems/rotate-array/
class Solution{
public static void main(String[] args) {
int[] a = {1, 2, 3, 5, 6, 7};
rotateArray(a, 3);
for (int i = 0; i < a.length; i++){
System.out.print(a[i]);
}
}
public static void rotateArray(int[] a, int k){