This file contains 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
int n = 4; | |
// 移位运算(注意溢出情况!) | |
int n1 = n << 1; // 这里相当于*2,n1:0b1000, 8 | |
int n2 = n >> 2; // n2: 0b1, 1 | |
// 与 | |
int n3 = n & 2; | |
// 或 | |
int n4 = n | 2; | |
// 取反/非 |
This file contains 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
// 完全背包问题 | |
public class Main { | |
public static void main(String[] args) { | |
int[] weight = {1, 3, 4}; | |
int[] value = {15, 20, 30}; | |
int bagSize = 4; | |
test2DimWeightBagProblem(weight, value, bagSize); | |
test1DimWeightBagProblem(weight, value, bagSize); | |
} |
This file contains 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
import java.util.*; | |
public class Main { | |
static int MAX_N = 10000; | |
static int[] inDegree = new int[MAX_N]; | |
// link是图的邻接表 | |
static List<Integer>[] link = new ArrayList[MAX_N]; | |
// n个节点,m个边 | |
static int n, m; |
This file contains 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
// Java Init an array of List | |
ArrayList[] graphArrayList = new ArrayList[4]; | |
for(int i=0;i<graphArrayList.length;i++){ | |
graphArrayList[i] = new ArrayList(); //数组的每一个元素都要new一个List对象,来初始化 | |
} |
This file contains 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
// 102.二叉树的层序遍历 | |
class Solution { | |
public List<List<Integer>> resList = new ArrayList<List<Integer>>(); | |
public List<List<Integer>> levelOrder(TreeNode root) { | |
//checkFun01(root,0); | |
checkFun02(root); | |
return resList; | |
} |
This file contains 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
import java.util.*; | |
/*Comparator接口说明: | |
* 返回负数,形参中第一个参数排在前面;返回正数,形参中第二个参数排在前面 | |
* 对于队列:排在前面意味着往队头靠 | |
* 对于堆(使用PriorityQueue实现):从队头到队尾按从小到大排就是最小堆(小顶堆), | |
* 从队头到队尾按从大到小排就是最大堆(大顶堆)--->队头元素相当于堆的根节点 | |
* */ | |
// 默认括号内的pair2>pair1,大的在队尾,升序 |
This file contains 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
import java.util.Random; | |
class Solution { | |
private final static Random random = new Random(System.currentTimeMillis()); | |
public int[] sortArray(int[] nums) { | |
quickSort(nums, 0, nums.length - 1); | |
return nums; |
This file contains 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
import sys | |
import os | |
import time | |
# 控制台输出记录到文件 | |
class Logger(object): | |
def __init__(self, file_name="Default.log", stream=sys.stdout): | |
self.terminal = stream | |
self.log = open(file_name, "a") |
This file contains 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
//binary search on a sorted arrays | |
public static int binarySearch(int[] nums,int target,int left,int right){ | |
while (left <= right) { | |
//这里需要注意,计算mid | |
int mid = left + ((right - left) >> 1); | |
if (nums[mid] == target) { | |
return mid; | |
}else if (nums[mid] < target) { | |
//这里需要注意,移动左指针 | |
left = mid + 1; |
This file contains 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
Java.perform(function () { | |
// 获得一个类的包装 | |
var classInstance = Java.use("de.fraunhofer.sit.premiumapp.LauncherActivity") | |
// hook 类实例的某一个方法 | |
classInstance.functionName.implementation = function() { | |
... | |
// 执行原来的方法,在获取某一个方法的返回值的时候十分有效 | |
this.functionName(); | |
}; |
NewerOlder