Skip to content

Instantly share code, notes, and snippets.

View Howiezhang226's full-sized avatar

Howard Zhang Howiezhang226

View GitHub Profile
@Howiezhang226
Howiezhang226 / day-of-the-year.java
Created January 27, 2020 07:28
Day of the Year
class Solution {
public int dayOfYear(String date) {
int[] daysOfTheMonth = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int days = 0;
String[] split = date.split("-");
int year = Integer.valueOf(split[0]);
int month = Integer.valueOf(split[1]);
int day = Integer.valueOf(split[2]);
for (int i = 0 ; i < month - 1; i++) {
days += daysOfTheMonth[i];
public class Solution {
public boolean canFinish(int numCourses, int[][] prereq) {
int[] visited = new int[numCourses];
List<List<Integer>> courses = new ArrayList<>();
for(int i=0;i<numCourses;i++){
courses.add(new ArrayList<Integer>());
}
for(int i=0;i< prereq.length;i++){
courses.get(prereq[i][1]).add(prereq[i][0]);
package c1s5;
/**
* Created by Hao Zhang on 2015/4/9.
*
*/
public class Solution {
/**
*aabbbcc => a1b3c2
*/
/*
1.4 Write a method to replace all spaces in a string with'%20'. You may assume that
the string has sufficient space at the end of the string to hold the additional
characters, and that you are given the "true" length of the string. (Note: if implementing
in Java, please use a character array so that you can perform this operation
in place.)
EXAMPLE
Input: "Mr John Smith"
@Howiezhang226
Howiezhang226 / Solution.java
Last active August 29, 2015 14:18
cc150_1_3
import java.util.Arrays;
public class Solution {
public String sortString(String str) {
char[] cstr = str.toCharArray();
Arrays.sort(cstr);
return new String(cstr);
}
/**
* created by howie zhang
* 2015/3/31
* cc150 1.1
*/
public class Solution {
public boolean isUnique(String s) {
if (s.length() > 256)
return false;
boolean[] all = new boolean[256];