Skip to content

Instantly share code, notes, and snippets.

View XDo0's full-sized avatar
🪐
Working from home

D0nnie XDo0

🪐
Working from home
View GitHub Profile
@XDo0
XDo0 / Bitwise.java
Created October 28, 2022 15:26
Java bitwise operation
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;
// 取反/非
@XDo0
XDo0 / CompleteKnapsack.java
Last active October 27, 2022 11:56
Knapsack Problem in java(背包问题)
// 完全背包问题
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);
}
@XDo0
XDo0 / TopologicalSort.java
Last active October 18, 2022 15:23
Java Graph Related ALgs
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;
@XDo0
XDo0 / ArrayofList.java
Created October 17, 2022 07:10
initialize data structure in java
// 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对象,来初始化
}
@XDo0
XDo0 / LevelOrder.java
Last active October 30, 2022 16:10
binary tree level order
// 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;
}
@XDo0
XDo0 / PriorityQueue.java
Last active November 7, 2022 09:27
Heap Sort based on PriorityQueue
import java.util.*;
/*Comparator接口说明:
* 返回负数,形参中第一个参数排在前面;返回正数,形参中第二个参数排在前面
* 对于队列:排在前面意味着往队头靠
* 对于堆(使用PriorityQueue实现):从队头到队尾按从小到大排就是最小堆(小顶堆),
* 从队头到队尾按从大到小排就是最大堆(大顶堆)--->队头元素相当于堆的根节点
* */
// 默认括号内的pair2>pair1,大的在队尾,升序
@XDo0
XDo0 / QuickSort.java
Last active October 10, 2022 08:15
quick sort [random select pivot](https://suanfa8.com/quick-sort/random-select-pivot)
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;
@XDo0
XDo0 / demo.py
Created June 10, 2022 07:44
python console2log
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")
@XDo0
XDo0 / BinarySearch.java
Last active May 3, 2022 14:26
Java Search
//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;
@XDo0
XDo0 / 1.js
Last active November 21, 2024 06:01
Useful Frida Scripts
Java.perform(function () {
// 获得一个类的包装
var classInstance = Java.use("de.fraunhofer.sit.premiumapp.LauncherActivity")
// hook 类实例的某一个方法
classInstance.functionName.implementation = function() {
...
// 执行原来的方法,在获取某一个方法的返回值的时候十分有效
this.functionName();
};