自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 Procedue of building rest API using Node, Express, PostgreSQL and Docker

【代码】Procedue of building rest API using Node, Express, PostgreSQL and Docker。

2022-10-17 08:20:18 222 1

原创 Fenwick Tree学习 灵魂画手 307. Range Sum Query - Mutable 线段树

这个人说的非常非常非常清晰,强烈推荐https://www.youtube.com/watch?v=uSFzHCZ4E-8对数组进行切分, 根据二进制排出父子节点。class BIT { int[] aux; public BIT(int[] nums) { aux = new int[nums.length + 1]; System.arraycopy(nums, 0, aux, 1, nums.length); for (int i

2021-03-30 21:35:12 123

原创 蚂蚁金服多线程面试题:三个线程ABC轮流打印1-100

public class TestThreadABC { public static void main(String[] args) { Print action = new Print(); new A(action, "A--->").start(); new B(action, "B--->").start(); new C(action, "C--->").start(); }}class

2021-02-26 10:29:29 855 1

原创 322. Coin Change 非常经典的动态规划问题

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, retu.

2021-02-07 11:55:26 211

原创 LEETCODE 979 Distribute Coins in Binary Tree

**Algs :This is a kind of Tree problem, so obviously, we can use a dfs to solve;for this problem, we want to fill each node with one coin, so we can ask left child if you have any coins left, please give them to me, then doing the same thing to the righ

2021-01-17 12:25:23 105

原创 42. Trapping Rain Water

给定一组数组,分别代表不同长度的柱子,求最大装水容量;https://leetcode.com/problems/trapping-rain-water/Example 1:Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: Theabove elevation map (black section) is represented by array[0,1,0,2,1,0,1,3,2,1,2,1]. In this c

2020-12-20 22:49:25 76

原创 LeetCode.46 & 47 全排列

PermutataionAlgs:基础回溯算法,列出每种可能性, 剪枝直接在每次递归最后撤销选择即可。public List<List<Integer>> permute(int[] nums) { List<List<Integer>> res = new ArrayList<>(); List<Integer> list = new ArrayList<>(); .

2020-12-07 23:50:22 97

原创 LeetCode 31. Next Permutation

题目: 给定一个数组, 找出其permutation中下一个大的permutation;解释: 按照从小到大的顺序,如果数组是12432, 那么需要返回13224, 即下一个比他大的数组。题解:1.从右往左遍历数组,一旦发现有降序相邻数组,即nums[i] > nums[i-1], 那么变化一定是在nums[i-1],使从i-1向后的数组成为原数组i-1向后数组的下一个最大permutation;2. 确定改变位置之后,需要找到下一个最大的值与i-1位置的值交换,这里注意,是要找到比nums[

2020-12-07 13:42:30 119

原创 LeetCode 287. Find the Duplicate Number

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.There is only one duplicate number in nums, return this duplicate number.Follow-ups:How can we prove that at least one duplicate number must ex

2020-12-04 13:58:11 113

原创 LeetCode3. Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters.Example 1:Input: s = “abcabcbb” Output: 3 Explanation: The answer is “abc”, withthe length of 3. Example 2:Input: s = “bbbbb” Output: 1 Explanation: The answer is

2020-12-03 11:26:33 74

原创 Algorithms Part II Maxflow 笔记

MinCut初始化是一个edge-weighted digraph, 有一个源点是s, 和目标点t;st-cut(cut)/ 割:将digraph的点分为两个不相连的集合,s在一个集合A,t在一个集合B;Capacity 从集合A到B的所有edge的容量总和;mincut : 拥有最小capacity的割问题;MaxFlowflow : 流,1. 小于等于该边容量;2. 输入流和输出流必须相等(除了s和t,在有向图中,假设s只有输出,t只有输入);##最大流问题就是找到输入目标终点的最大流

2020-11-30 11:28:47 201

原创 300. Longest Increasing Subsequence

Given an integer array nums, return the length of the longest strictlyincreasing subsequence.A subsequence is a sequence that can be derived from an array bydeleting some or no elements without changing the order of theremaining elements. For example,.

2020-11-19 11:26:30 84

原创 Direct Graph

Topological Sort重置不含有循环的图, 使所有连接都指向上面。算法:后序遍历graph, 并插入到stack; stack将其方向调换。// postOrder : operate when the pointer leaves the node// a diagraph may have topological order if there is no directed cycle!!!class TopologicalSort { boolean[] marked; Sta

2020-11-05 11:00:47 289

原创 Princeton Algorithms. QuickSort

Algorithm打乱数组;随机挑选一个值(一般取第一个),使得它的左侧全部小于他,右侧全部大于他;(用两个指针,一个遍历找到小于它的,一个遍历找到大于它的, 如果发现未知反了,那么交换两个指针当前位置的值)将左右部分递归,得出有序数组Implementation:4. 找到索引位置private int partition(Comparable[] a, int lo, int hi) { int i = lo; int j = hi; while (true) { // 找到需

2020-10-15 12:28:11 100

原创 Princeton Algorithm ElementarySort

1. Selection SortAlgorithm:一个指针遍历数组,另一个指针遍历后面位置的值并找到最小值,与当前指针位置的值进行交换。时间复杂度O(N^2).public void selectionSort(int[] a) { int size = a.length; for (int i = 0; i < size; i++) { // 选择当前遍历到的点作为最小值 int min = i; // 然后遍历后面的数,找到最小值,并且替换到当前位置 for (int

2020-10-14 10:59:37 131

原创 Leetcode.993 Cousins in BST

In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.Two nodes of a binary tree are cousins if they have the same depth, but have different parents.We are given the root of a binary tree with unique values, an

2020-10-05 12:18:23 82

原创 Leetcode 78 子集 & 90 子集II & leetcode 46全排列 回溯算法总结

78.Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]暴力解求子集,先加一个空集,.

2020-09-24 20:04:03 114

原创 LeetCode 694不同岛屿数量

Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.Count the number of distinct islands. A.

2020-09-17 13:56:39 577

原创 LeetCode 216组合总和III

找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。说明:所有数字都是正整数。解集不能包含重复的组合。示例 1:输入: k = 3, n = 7输出: [[1,2,4]]示例 2:输入: k = 3, n = 9输出: [[1,2,6], [1,3,5], [2,3,4]]来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/combination-sum-iii著作权归领

2020-09-11 16:49:12 109

原创 LeetCode 257 二叉树的所有路径

给定一个二叉树,返回所有从根节点到叶子节点的路径。说明: 叶子节点是指没有子节点的节点。示例:输入:1/ 2 35输出: [“1->2->5”, “1->3”]解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->31.DFS(递归)class Solution{ public List<String> binaryTreePaths(TreeNode root) { List<String> r

2020-09-04 10:48:54 90

原创 LeetCode 200岛屿数量 (UnionFind)

跟完CS61B的UnionFind不久,所以看到这题第一反应是并查集解。给你一个由 ‘1’(陆地)和 ‘0’(水)组成的的二维网格,请你计算网格中岛屿的数量。岛屿总是被水包围,并且每座岛屿只能由水平方向或竖直方向上相邻的陆地连接形成。此外,你可以假设该网格的四条边均被水包围。示例 1:输入: [ [‘1’,‘1’,‘1’,‘1’,‘0’], [‘1’,‘1’,‘0’,‘1’,‘0’],[‘1’,‘1’,‘0’,‘0’,‘0’], [‘0’,‘0’,‘0’,‘0’,‘0’] ]输出: 1

2020-08-23 21:12:20 119

原创 CS61B Tries 听课笔记

**1.Basic Trie Impletation**Public class TrieSet{ private static final int R =128; //ASCII private NOde root; public class DataIndexedCharMap<V> { private V[] items; public DataIndexedCharMap(int R) { items = (V[]) new Object

2020-08-17 16:36:38 228

原创 cs 61b Heaps and PQs

The priority Queue: Allowing tracking and removal of the smallest item in a priority queue.找到每天最大的几条信息,下面是直接的方法public List<String> unharmoniousTexts(Sniffer sniffer, int M) { ArrayList<String>allMessages = new ArrayList<String>();

2020-08-12 10:38:56 186

原创 leetcode 9.回文(easy)

判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。示例 1:输入: 121输出: true示例 2:输入: -121输出: false解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。示例 3:输入: 10输出: false解释: 从右向左读, 为 01 。因此它不是一个回文数。1.暴力解,转化为StringBuilder直接翻转class Solution { public boolean

2020-08-04 16:12:47 87

原创 CS61B discussion3 1.2 翻转列表 同leetcode206

反转一个单链表。示例:输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NULL进阶:你可以迭代或递归地反转链表。你能否用两种方法解决这道题?来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/reverse-linked-list著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。1.首先用迭代;class Solution {

2020-07-16 12:49:21 174

原创 CS106A boolean

/* bollean 只返回true&flase*/public boolean IsEven(int n) { if (n & 2 == 0) { return ture; } else{ return false;` }}//或者可以简化写成//public boolean xxx(int balabla){ return balabla + 6 //if condition// //条件达

2020-07-12 22:16:28 132

原创 CS 61B week 2 extraIntListPractice

/** Returns an IntList identical to L, but with * each element incremented by x. L is not allowed * to change. */ public static IntList incrList(IntList L, int x) { if (L == null ){ return null;// }else {

2020-07-12 16:53:21 597

原创 初学者CS61B week 2笔记

IntList————public class IntLIst(){ public int first;// 声明变量,类型是int public IntList rest;//类型是intlist public IntList(int f, IntList r){ First=f; rest=r; //constructor,初始化变量 } }实现size和iterativesize方法public int

2020-07-12 15:45:16 426 3

原创 cs106a assignment2 target

import acm.graphics.*;import acm.program.*;import java.awt.*;public class Target extends GraphicsProgram { double static final pixels = 72; double static final outer_radius = 1 * pixels; double static final middle_radius = 0.65*pixels; double stat

2020-06-18 21:49:43 139

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除