This file contains hidden or 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
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains hidden or 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
// 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){ |
This file contains hidden or 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
//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]; | |
This file contains hidden or 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
//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>>(); |
This file contains hidden or 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
//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] |
This file contains hidden or 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 algorithm.sort; | |
class ListNode { | |
int val; | |
ListNode next; | |
ListNode(int x) { | |
val = x; | |
next = null; | |
} |
This file contains hidden or 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
//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]; |
This file contains hidden or 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
//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; } | |
* } | |
*/ |
This file contains hidden or 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
//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; | |
} | |
} |
This file contains hidden or 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
//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(" "); |