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/submissions/detail/90614988/ | |
* 二分 + 确界 判断 | |
*/ | |
public int splitArray(int[] nums, int m) { | |
long right = 1;//右界是总和 | |
for(int i = 0; i<nums.length; ++i){ | |
right +=nums[i]; | |
} | |
long left = 0,ans = 0; |
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/kth-smallest-element-in-a-sorted-matrix/ | |
//--------------------------------------------------------------- | |
// one v | |
public class Solution { | |
public int kthSmallest(int[][] matrix, int k) { | |
int n = matrix.length; | |
long left = matrix[0][0], right = matrix[n - 1][n - 1]; | |
while(left <= right){ |
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/rotate-array/ | |
public static void rotate(int[] arr, int order) { | |
if (arr == null || arr.length==0 || order < 0) { | |
throw new IllegalArgumentException("Illegal argument!"); | |
} | |
if(order > arr.length){ | |
order = order %arr.length; | |
} | |
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/rotate-array/ | |
public void rotate0(int[] nums, int k) { | |
if(k > nums.length) | |
k=k%nums.length; | |
int[] result = new int[nums.length]; | |
for(int i=0; i < k; i++){ | |
result[i] = nums[nums.length-k+i]; | |
} |
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/powx-n/ | |
public class Solution { | |
public double myPow(double x, int n) { | |
//x^n = e^(x*ln x) | |
int flag = 1; | |
if(x < 0 && n%2 != 0){ | |
flag = -1; | |
} | |
x = Math.abs(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/ | |
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(" "); |
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/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/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
package algorithm.sort; | |
class ListNode { | |
int val; | |
ListNode next; | |
ListNode(int x) { | |
val = x; | |
next = null; | |
} |