This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package c1s5; | |
/** | |
* Created by Hao Zhang on 2015/4/9. | |
* | |
*/ | |
public class Solution { | |
/** | |
*aabbbcc => a1b3c2 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class Solution { | |
public String sortString(String str) { | |
char[] cstr = str.toCharArray(); | |
Arrays.sort(cstr); | |
return new String(cstr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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]; |