Skip to content

Instantly share code, notes, and snippets.

View wushbin's full-sized avatar

Shengbin Wu wushbin

  • San Francisco Bay Area
View GitHub Profile
class Solution {
public String dayOfTheWeek(int day, int month, int year) {
int dayDiff = getDayDiff(day, month, year);
int currDayDiff = getDayDiff(9, 2, 2020);
int diff = dayDiff - currDayDiff;
int shift = diff % 7;
shift = (shift + 7) % 7;
String[] dict = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int currDayIndex = 0;
/**
Two pass solution
**/
class Solution {
public String getHint(String secret, String guess) {
if (secret == null || guess == null || secret.length() == 0 || guess.length() == 0) {
return "";
}
int len = secret.length();
class Solution {
public String decodeString(String s) {
if (s == null || s.length() == 0) {
return "";
}
return decode(s.toCharArray(), new int[]{0});
}
public String decode(char[] s, int[] p) {
StringBuilder result = new StringBuilder();
class Solution {
public int findMinDifference(List<String> timePoints) {
List<Integer> times = new ArrayList<>();
for (String tp : timePoints) {
times.add(readValue(tp));
}
Collections.sort(times);
int min = Integer.MAX_VALUE;
int len = times.size();
class Solution {
public void rotate(int[][] matrix) {
trans(matrix);
flip(matrix);
}
private void trans(int[][] matrix) {
int row = matrix.length;
int col = matrix[0].length;
for (int i = 0; i < row; i++) {
class Solution {
public int myAtoi(String str) {
if (str == null || str.length() == 0) {
return 0;
}
int ptr = 0;
int len = str.length();
while(ptr < len && str.charAt(ptr) == ' ') {
ptr++;
class Solution {
public boolean isPalindrome(String s) {
int l = 0;
int r = s.length() - 1;
while(l < r) {
while(l < r && !Character.isLetter(s.charAt(l)) && !Character.isDigit(s.charAt(l)) ) {
l++;
}
char lc = Character.toLowerCase(s.charAt(l));
class Solution {
public boolean validTicTacToe(String[] board) {
int[] row = new int[3];
int[] col = new int[3];
int diag = 0;
int anti = 0;
int xMove = 0;
int oMove = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
class Solution {
public String validIPAddress(String IP) {
String[] ipv4 = IP.split("\\.");
String[] ipv6 = IP.split("\\:");
if (ipv4.length == 4) {
if (countSep(IP, '.') > 3) {
return "Neither";
}
for (int i = 0; i < 4; i++) {
/**
Solution One
Two Pass
**/
class Solution {
public String convert(String s, int numRows) {
if (s == null || s.length() == 0 || numRows == 0) {
return "";
}
if (numRows == 1) {