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
//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);
//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];
}
//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;
}
//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){
/**
* 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;
public int mySqrt(int x) {
long left = 0, right = x/2 +1;
long ans = 0;
while(left <= right){
long mid = (left + right) / 2;
if(mid * mid <= x){
ans = mid;
left = mid + 1;
} else {
right = mid - 1;
//https://leetcode.com/problems/sqrtx/
public int mySqrt(int y) {
//return (int)Math.sqrt(x);
long L = 0, R = (long)y + 1;//[0,y)
long ans = 0;
while(L < R){
long mid = (L + R) / 2;// guess mid
if(guess(mid, y)){
ans = mid;
L = mid + 1;
//https://leetcode.com/problems/sqrtx/
public int mySqrt(int x) {
if (x == 0) return 0;
double last = 0;
double res = 1;
while (res != last)
{
last = res;
res = (res + x / res) / 2;
}
// 根据Unicode编码完美的判断中文汉字和符号
private static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
@Chen-tao
Chen-tao / git_toturial
Created December 19, 2016 08:40 — forked from guweigang/git_toturial
git命令大全
git init # 初始化本地git仓库(创建新仓库)
git config --global user.name "xxx" # 配置用户名
git config --global user.email "[email protected]" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://[email protected]/VT.git # clone远程仓库