Skip to content

Instantly share code, notes, and snippets.

View Chen-tao's full-sized avatar

Chen-tao Chen-tao

  • ByteDance
  • Beijing China
View GitHub Profile
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
// https://leetcode.com/problems/subsets-ii/
public class Solution {
public static List<List<Integer>> ans = new ArrayList<List<Integer>>();
//public static int[] path = new int[100];
public static boolean[] v = new boolean[100];
public static void robot(int idx, int[] nums){
//https://leetcode.com/problems/subsets/
//深搜 框架解法
public class Solution {
public static List<List<Integer>> ans = new ArrayList<List<Integer>>();
//public static int[] path = new int[100];
public static boolean[] v = new boolean[100];
//https://leetcode.com/problems/subsets/
//一种思路
public class Solution {
/*
* Given a set S of n distinct integers, there is a relation between Sn and Sn-1. The subset
* of Sn is the union of subset of Sn-1 and each element in Sn-1 + one more element.
* Therefore, a Java solution can be quickly formalized.
*/
public static List<List<Integer>> ans = new ArrayList<List<Integer>>();
//https://leetcode.com/problems/combinations/
// 深度优先搜索框架
public class Solution {
public static List<List<Integer>> ans = new ArrayList<List<Integer>>();
public static int[] path = new int[100];
public static int K = 0;
public static void robot(int idx, int n, int k){//idx [0, n]
package algorithm.sort;
class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
//https://leetcode.com/problems/permutations/
/**
* 深度优先搜索框架
*/
public class Solution {
public static List<List<Integer>> ans = new ArrayList<List<Integer>>();
public static int[] path = new int[100];
public static boolean[] v = new boolean[100];
//https://leetcode.com/problems/path-sum/
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
//https://leetcode.com/problems/reverse-words-in-a-string/
// O(1) space v
public void reverseWords(char[] s) {
int i=0;
for(int j=0; j<s.length; j++){
if(s[j]==' '){
reverse(s, i, j-1);
i=j+1;
}
}
//https://leetcode.com/problems/reverse-words-in-a-string/
public class Solution {
public String reverseWords(String s) {
if (s == null || s.length() == 0) {
return "";
}
StringBuilder ans = new StringBuilder();
s = s.trim().replaceAll(" +", " ");
String[] anss = s.split(" ");