Skip to content

Commit

Permalink
new update for learning note
Browse files Browse the repository at this point in the history
  • Loading branch information
rbmonster committed Jan 31, 2021
1 parent 7795c21 commit badf1ee
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 16 deletions.
37 changes: 36 additions & 1 deletion src/main/java/com/design/INTERFACE_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,39 @@ Content-Type: application/json
- RestControllerAdvice顾名思义,就是声明了范围内的RestController的建议处理控制

### 使用swagger暴露参数
- Swagger是一种广泛使用的工具来用来记录与呈现 REST API,它提供了一种探索特定 API 使用的方法,因此允许开发人员理解底层的语义行为。
- Swagger是一种广泛使用的工具来用来记录与呈现 REST API,它提供了一种探索特定 API 使用的方法,因此允许开发人员理解底层的语义行为。

## 接口安全相关

### API Token(接口令牌)

1. 接口调用方(客户端)向接口提供方(服务器)申请接口调用账号,申请成功后,接口提供方会给接口调用方一个appId和一个key参数
2. 客户端携带参数appId、timestamp、sign去调用服务器端的API token,其中sign=加密(appId + timestamp + key)
3. 客户端拿着api_token 去访问不需要登录就能访问的接口
4. 当访问用户需要登录的接口时,客户端跳转到登录页面,通过用户名和密码调用登录接口,登录接口会返回一个usertoken, 客户端拿着usertoken 去访问需要登录才能访问的接口
> sign的作用是防止参数被篡改,客户端调用服务端时需要传递sign参数,服务器响应客户端时也可以返回一个sign用于客户度校验返回的值是否被非法篡改了。客户端传的sign和服务器端响应的sign算法可能会不同。
验证参数放置在请求头
```
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String token = request.getHeader("token");
String timestamp = request.getHeader("timestamp");
// 随机字符串
String nonce = request.getHeader("nonce");
String sign = request.getHeader("sign");
}
```


### 攻击行为防御
1. 错误达到3次,验证码或者滑块验证
2. 错误达到10次,手机验证码验证登陆。
3. IP限制
> 不能直接根据错误次数封死账号登陆,可能会导致整个系统的账户都被黑客暴力破解至无法登陆。


### 相关资料
- 接口安全设计:https://mp.weixin.qq.com/s/Az17l4SJXvcbXNu4A1j1Xg
- 接口可能遇到的攻击:https://mp.weixin.qq.com/s/j0wjQLwkcXnRx7YTU6Lssg
26 changes: 23 additions & 3 deletions src/main/java/com/learning/algorithm/ALGORITHM.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,22 @@ private int maximum_depth(TreeNode root) {
构造二叉树问题:
- 从前序与中序遍历序列构造二叉树:https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
- 从中序与后序遍历序列构造二叉树:https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/

- 层序遍历构建二叉树思路: 根节点区分两个区间,获取中序左区间内的Set。遍历层序数组,第一个节点即为根节点。
- ```
ori:
in[] = {4, 8, 10, 12, 14, 20, 22};
level[] = {20, 8, 22, 4, 12, 10, 14};
20
/ \
/ \
{4,8,10,12,14} {22}
next:
In[] = {4, 8, 10, 12, 14}
level[] = {8, 4, 12, 10, 14}
```
公共祖先问题:
- 二叉树的最近公共祖先:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/
Expand Down Expand Up @@ -573,12 +588,17 @@ public int[] maxSlidingWindow(int[] nums, int k) {
它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高。
### 贪心算法
## 贪心算法
[CS-Note](http://www.cyc2018.xyz/%E7%AE%97%E6%B3%95/Leetcode%20%E9%A2%98%E8%A7%A3/Leetcode%20%E9%A2%98%E8%A7%A3%20-%20%E8%B4%AA%E5%BF%83%E6%80%9D%E6%83%B3.html#_1-%E5%88%86%E9%85%8D%E9%A5%BC%E5%B9%B2)
1. [分配饼干](https://leetcode-cn.com/problems/assign-cookies/description/)
- 每次分配给满足孩子的最小的饼干
2. [不重叠的区间个数](https://leetcode-cn.com/problems/non-overlapping-intervals/)
- 每次取结尾最小的区间,留给后面选择的区间更大,移除的区间越小。按区间结尾排序。
3. [投飞镖刺破气球](https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/)
- 与上述类似,每次取结尾最小的区间,
- 与上述类似,每次取结尾最小的区间,
## TODO List
计算1的个数
45 changes: 37 additions & 8 deletions src/main/java/com/learning/algorithm/Demo2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.learning.algorithm;

import com.learning.algorithm.basic.treeNode.TreeNode;

import java.util.*;

/**
Expand All @@ -17,7 +19,7 @@ public class Demo2 {
public static void main(String[] args) {
new Demo2().reverseWords("the sky is blue");

PriorityQueue<Integer> queue = new PriorityQueue<>((o1,o2) -> o2-o1);
PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> o2 - o1);

}

Expand All @@ -43,7 +45,7 @@ public String reverseWords(String s) {
}


int res = 0;
int res = 0;

public int translateNum(int num) {
String str = String.valueOf(num);
Expand All @@ -59,12 +61,12 @@ public void dfs(String str, int index) {
res++;
return;
}
dfs(str, index+1);
int cur = str.charAt(index)-'0';
if (cur >0 && cur<=2 && index+1<len ) {
int next = str.charAt(index+1)-'0';
if (cur == 2&& next>5) return;
dfs(str, index+2);
dfs(str, index + 1);
int cur = str.charAt(index) - '0';
if (cur > 0 && cur <= 2 && index + 1 < len) {
int next = str.charAt(index + 1) - '0';
if (cur == 2 && next > 5) return;
dfs(str, index + 2);
}
}

Expand Down Expand Up @@ -110,4 +112,31 @@ public int eraseOverlapIntervals(int[][] intervals) {
}
return result;
}

public TreeNode reConstructBinaryTree(int[] pre, int[] in) {
if (pre == null || in == null) {
return null;
}

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < in.length; i++) {
map.put(in[i], i);
}

return preIn(pre, 0, pre.length - 1, in, 0, in.length - 1, map);
}

public TreeNode preIn(int[] p, int pi, int pj, int[]
n, int ni, int nj, Map<Integer, Integer> map) {

if (pi > pj) {
return null;
}
TreeNode head = new TreeNode(p[pi]);
int index = map.get(p[pi]); //这样比原始方案一的方式效率要高,值得思考的地方
head.left = preIn(p, pi + 1, pi + index - ni, n, ni, index - 1, map);
head.right = preIn(p, pi + index - ni + 1, pj, n, index + 1, nj, map);
return head;
}

}
8 changes: 8 additions & 0 deletions src/main/java/com/learning/basic/COLLECTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,11 @@ public class Arrays{
}
}
```
### hash 冲突解决方案
1. 链地址法:HashMap中hash冲突节点,使用链表和红黑树解决
2. 线性探测再散列:ThreadLocal中ThreadLocalMap的hash冲突,会线性向后探索直到寻找到向下一个空的节点。
3. 再哈希法。
> 这种方法是同时构造多个不同的哈希函数:Hi=RH1(key) i=1,2,…,k。当哈希地址Hi=RH1(key)发生冲突时,再计算Hi=RH2(key)……,直到冲突不再产生。
- [Hash冲突的四种解决办法](https://www.cnblogs.com/gongcheng-/p/10894205.html#_label1_0)
Loading

0 comments on commit badf1ee

Please sign in to comment.