Skip to content

Instantly share code, notes, and snippets.

View Cee's full-sized avatar
πŸŽ€
ハネだ (<ゝω·)β˜†

Tianyu Wang Cee

πŸŽ€
ハネだ (<ゝω·)β˜†
View GitHub Profile
public class Solution {
public String reverseWords(String s) {
s = s.trim();
int n = s.length();
String str = "";
while(s.lastIndexOf(" ") != -1){
int index = s.lastIndexOf(" ");
str = str + s.substring(index + 1, n) + " ";
s = s.substring(0, index).trim();
n = s.length();
public class Solution {
public int singleNumber(int[] A) {
int[] count = new int[32];
int result = 0;
for (int i = 0; i < 32; i++) {
for (int j = 0; j < A.length; j++) {
if (((A[j] >> i) & 1) == 1) {
count[i]++;
}
}
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
public class Solution {
public int maxProfit(int[] prices) {
int ret = 0;
int index = 0;
while (index < prices.length){
if (index + 1 < prices.length){
if (prices[index] < prices[index + 1]){
ret += prices[index + 1] - prices[index];
}
}
public class Solution {
public int numTrees(int n) {
if (n == 0) return 1;
if (n == 1) return 1;
if (n == 2) return 2;
int ret = 0;
for (int i = 1; i <= n; i++){
ret = ret + numTrees(i - 1) * numTrees(n - i);
}
return ret;
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public class Solution {
public int climbStairs(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
int ret = 0;
int tempa = 2;
int tempb = 1;
for (int i = 3; i <= n; i++){
ret = tempa + tempb;
public class Solution {
public int maxSubArray(int[] A) {
int sum = Integer.MIN_VALUE;
int ret = Integer.MIN_VALUE;
int length = A.length;
for(int i = 0; i < A.length; i++){
if (sum < 0){
sum = A[i];
}else{
sum += A[i];