Skip to content

Instantly share code, notes, and snippets.

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

Tianyu Wang Cee

πŸŽ€
ハネだ (<ゝω·)β˜†
View GitHub Profile
/**
* 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 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;
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];
}
}
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
/**
* 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 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]++;
}
}
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();
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
public class Solution {
public int divide(int dividend, int divisor) {
long a = dividend;
long b = divisor;
if (a == 0) return 0;
boolean flag = (a > 0) ^ (b > 0);
if (a < 0) a = -a;
if (b < 0) b = -b;
if (a < b) return 0;
long ret = 0;