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
public class Solution {
public int longestPalindrome(String s) {
int m = 0;
int n = 0;
Map<Character, Integer> cache = new HashMap<Character, Integer>();
char[] sc = s.toCharArray();
for(char c : sc){
if(cache.get(c) != null){
cache.put(c, cache.get(c) + 1);
} else {
@Chen-tao
Chen-tao / quick_sort.java
Last active February 6, 2017 02:51
Quicksort is a divide and conquer algorithm. It first divides a large list into two smaller sub-lists and then recursively sort the two sub-lists. If we want to sort an array without any extra space, quicksort is a good option. On average, time complexity is O(n log(n)). The basic step of sorting an array are as follows: - Select a pivot, normal…
public class QuickSort {
public static void main(String[] args) {
int[] x = { 9, 2, 4, 7, 3, 7, 10 };
System.out.println(Arrays.toString(x));
int low = 0;
int high = x.length - 1;
quickSort(x, low, high);
System.out.println(Arrays.toString(x));
@Chen-tao
Chen-tao / longestPalindrome_ Manacher.java
Created February 5, 2017 03:43
Manacher算法,时间复杂度O(n), 空间复杂度O(n)
public class Solution {
public String longestPalindrome(String s) {
String T = preProcess(s);
int n = T.length();
int[] p = new int[n];
int center = 0, right = 0;
for (int i = 1; i < n - 1; i++) {
int j = 2 * center - i; //j and i are symmetric around center
p[i] = (right > i) ? Math.min(right - i, p[j]) : 0;
@Chen-tao
Chen-tao / longestPalindrome.java
Last active February 5, 2017 03:40
动态规划,列举回文串的起点或者终点来解最长回文串问题,无需讨论串长度的奇偶性
public int longestPalindrome(String s) {
int n=s.length();
boolean[][] pal=new boolean[n][n];
//pal[i][j] 表示s[i...j]是否是回文串
int maxLen=0;
for (int i=0;i<n;i++){ // i作为终点
int j=i; //j作为起点
while (j>=0){
if (s.charAt(j)==s.charAt(i)&&(i-j<2||pal[j+1][i-1])){
pal[j][i]=true;
ls | sed "s:^:`pwd`/: "
find . -type f -size +200M -print0 | xargs -0 du -h | sort -nr
tcpdump -XplAs0 -xxvvv -i any
//https://leetcode.com/problems/combination-sum/
//模版思路 解法
public class Solution {
public static List<List<Integer>> result = new ArrayList<List<Integer>>();
public static int[] path = new int[100];
public static int len = 0;
public List<List<Integer>> combinationSum(int[] candidates, int target) {
result.clear();
//https://leetcode.com/problems/combination-sum/
public class Solution {
public List<List<Integer>> combinationSum(int[] candidates, int target) {
List<List<Integer>> result = new ArrayList<List<Integer>>();
if (candidates == null || candidates.length == 0)
return result;
ArrayList<Integer> current = new ArrayList<Integer>();
//https://leetcode.com/problems/combination-sum-iii/
public class Solution {
//ans
public static List<List<Integer>> result = new ArrayList<List<Integer>>();
public static List<List<Integer>> combinationSum3(int k, int n) {
result.clear();
List<Integer> curr = new ArrayList<Integer>();