From 49f2850c5eeead43e65b31d68b694c2d3b81f684 Mon Sep 17 00:00:00 2001 From: DuHouAn <18351926682@163.com> Date: 2019年7月25日 23:46:18 +0800 Subject: [PATCH 1/4] Java --- ...345円215円260円351円223円276円350円241円250円.java" | 32 +++++++ ...347円232円204円346円225円260円345円255円227円.java" | 38 +++++++++ ...345円276円205円345円244円204円347円220円206円.java" | 37 +++++++++ ...347円247円257円346円225円260円347円273円204円.java" | 36 ++++++++ ...347円232円204円350円267円257円345円276円204円.java" | 83 +++++++++++++++++++ 5 files changed, 226 insertions(+) create mode 100644 "docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" create mode 100644 "docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" create mode 100644 "docs/AimForOffer/346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円_345円276円205円345円244円204円347円220円206円.java" create mode 100644 "docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" create mode 100644 "docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" diff --git "a/docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" "b/docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" new file mode 100644 index 0000000..c73507b --- /dev/null +++ "b/docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" @@ -0,0 +1,32 @@ +import java.util.ArrayList; + +/** + * Created by DHA on 2019年7月22日. + */ +public class 从尾到头打印链表 { + //从尾到头打印链表 + public ArrayList printListFromTailToHead(ListNode listNode) { + ArrayList res = new ArrayList(); + + //逆置该链表 + ListNode head = reverse(listNode); + while(head!=null){ + res.add(head.val); + head = head.next; + } + return res; + } + + private ListNode reverse(ListNode listNode){ + ListNode pre = null; + ListNode cur = listNode; + while(cur!=null){ + ListNode next = cur.next; + cur.next = pre; + + pre = cur; + cur = next; + } + return pre; + } +} diff --git "a/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" "b/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" new file mode 100644 index 0000000..3dd4684 --- /dev/null +++ "b/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" @@ -0,0 +1,38 @@ +import org.junit.Test; + +/** + * Created by DHA on 2019年7月22日. + */ +public class 数组中重复的数字 { + //数组中重复的数字 + public boolean duplicate(int numbers[],int length,int [] duplication) { + for(int i=0;i0){ + sum += num %10; + num/=10; + } + return sum; + } + + + + public int movingCount(int threshold, int rows, int cols) { + + } + + @Test + public void test(){ + int num = 37; + System.out.println(getNum(num)); + } +} diff --git "a/docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" "b/docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" new file mode 100644 index 0000000..bb5acd5 --- /dev/null +++ "b/docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" @@ -0,0 +1,36 @@ +import org.junit.Test; + +/** + * Created by DHA on 2019年7月22日. + */ +public class 构建乘积数组 { + //构建乘积数组 + //思路: + //B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。 + //B[i] 可拆分成 (A[0]*A[1]*...*A[i-1])*(A[i+1]*...*A[n-1])两部分 + public int[] multiply(int[] A) { + int n = A.length; + int[] B = new int[n]; + + //B[i] = A[0]*A[1]*...*A[i-1] + int product =1; + for(int i=0;i=0;product*=A[i],i--){ + B[i]*= product; + } + return B; + } + + @Test + public void test(){ + int[] A={1,2,3,4,5}; + int[] B=multiply(A); + for(int num:B){ + System.out.println(num); + } + } +} diff --git "a/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" "b/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" new file mode 100644 index 0000000..37c982c --- /dev/null +++ "b/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" @@ -0,0 +1,83 @@ +import org.junit.Test; + +/** + * Created by DHA on 2019年7月25日. + */ +public class 矩阵中的路径 { + private int m,n; //矩阵的长度、宽度 + private boolean[][] visted; //标记是否访问 + + private int[][] d={ + {0,1}, //向右 + {-1,0},//向上 + {0,-1},//向左 + {1,0} //向下 + }; + + private boolean inArea(int x,int y){ + return (x>=0 && x=0 && y Date: 2019年8月14日 20:29:41 +0800 Subject: [PATCH 2/4] Java --- docs/AimForOffer/MyQueue.java | 56 +++++++++++++ docs/AimForOffer/ThreadSafeLRUCache.java | 49 ++++++++++++ docs/AimForOffer/TreeLinkNode.java | 13 +++ docs/AimForOffer/TreeNode.java | 9 +++ ...52347円273円223円347円202円271円_Important.java" | 31 ++++++++ ...63345円217円260円351円230円266円_Important.java" | 32 ++++++++ ...344円272円214円345円217円211円346円240円221円.java" | 30 +++++++ ...347円232円204円346円225円260円345円255円227円.java" | 13 +-- ...17346円225円260円345円255円227円_Important.java" | 58 ++++++++++++++ ...42347円251円272円346円240円274円_Important.java" | 43 ++++++++++ ...347円216円260円351円230円237円345円210円227円.java" | 35 ++++++++ ...42350円246円206円347円233円226円_Important.java" | 37 +++++++++ ...347円232円204円350円267円257円345円276円204円.java" | 79 +------------------ ...350円267円263円345円217円260円351円230円266円.java" | 29 +++++++ 14 files changed, 424 insertions(+), 90 deletions(-) create mode 100644 docs/AimForOffer/MyQueue.java create mode 100644 docs/AimForOffer/ThreadSafeLRUCache.java create mode 100644 docs/AimForOffer/TreeLinkNode.java create mode 100644 docs/AimForOffer/TreeNode.java create mode 100644 "docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" create mode 100644 "docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" create mode 100644 "docs/AimForOffer/345円273円272円344円272円214円345円217円211円346円240円221円.java" create mode 100644 "docs/AimForOffer/346円227円213円350円275円254円346円225円260円347円273円204円347円232円204円346円234円200円345円260円217円346円225円260円345円255円227円_Important.java" create mode 100644 "docs/AimForOffer/346円233円277円346円215円242円347円251円272円346円240円274円_Important.java" create mode 100644 "docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" create mode 100644 "docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" create mode 100644 "docs/AimForOffer/350円267円263円345円217円260円351円230円266円.java" diff --git a/docs/AimForOffer/MyQueue.java b/docs/AimForOffer/MyQueue.java new file mode 100644 index 0000000..59d933c --- /dev/null +++ b/docs/AimForOffer/MyQueue.java @@ -0,0 +1,56 @@ +import java.util.Stack; + +/** + * Created by 18351 on 2019年7月23日. + */ +//使用两个栈实现队列的扩展 +public class MyQueue { + //用两个栈实现队列 + Stack stack1 = new Stack(); + Stack stack2 = new Stack(); + + //存储队列头元素 + private int front; //方便后面的 peek() 操作 + + /** Initialize your data structure here. */ + public MyQueue() { + stack1 = new Stack(); + stack2 = new Stack(); + } + + public void push(int node) { + if(stack1.isEmpty()){ + front = node; + } + stack1.push(node); + } + + public int pop() { + if(stack2.isEmpty()){ + while(!stack1.isEmpty()){ + stack2.push(stack1.pop()); + } + } + return stack2.pop(); + } + + public int peek(){ + if(stack2.isEmpty()){ + return front; + } + return stack2.peek(); + } + + public boolean empty(){ + return (stack1.isEmpty()) && (stack2.isEmpty()); + } + + public static void main(String[] args) { + MyQueue queue = new MyQueue(); + queue.push(1); + queue.push(2); + System.out.println(queue.peek()); // 返回 1 + System.out.println(queue.pop()); // 返回 1 + queue.empty(); // 返回 false + } +} diff --git a/docs/AimForOffer/ThreadSafeLRUCache.java b/docs/AimForOffer/ThreadSafeLRUCache.java new file mode 100644 index 0000000..b725030 --- /dev/null +++ b/docs/AimForOffer/ThreadSafeLRUCache.java @@ -0,0 +1,49 @@ +import org.junit.Test; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Created by 18351 on 2019年7月25日. + */ +public class ThreadSafeLRUCache { + private static final int MAX_CAPACITY = 3; + private LinkedHashMap linkedHashMap; + + public ThreadSafeLRUCache(){ + linkedHashMap = new LinkedHashMap(MAX_CAPACITY,0.75f,false){ + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size()>MAX_CAPACITY; + } + }; + } + + public synchronized void put(K k,V v){ + linkedHashMap.put(k,v); + } + + public synchronized V get(K k){ + return (V)linkedHashMap.get(k); + } + + @Override + public String toString() { + StringBuilder sb=new StringBuilder(); + for(Map.Entry entry:linkedHashMap.entrySet()) + sb.append(String.format("%s: %s\n", entry.getKey(), entry.getValue())); + return sb.toString(); + } + + @Test + public void test(){ + ThreadSafeLRUCache cache=new ThreadSafeLRUCache(); + cache.put(1, "a"); + cache.put(2, "b"); + cache.put(3, "c"); + cache.get(1); + //LRU 键值1被访问过了,则最近最久未访问的就是2 + cache.put(4, "d"); + System.out.println(cache); + } +} diff --git a/docs/AimForOffer/TreeLinkNode.java b/docs/AimForOffer/TreeLinkNode.java new file mode 100644 index 0000000..c277e9e --- /dev/null +++ b/docs/AimForOffer/TreeLinkNode.java @@ -0,0 +1,13 @@ +/** + * Created by 18351 on 2019年7月23日. + */ +public class TreeLinkNode { + int val; + TreeLinkNode left = null; + TreeLinkNode right = null; + TreeLinkNode next = null; + + TreeLinkNode(int val) { + this.val = val; + } +} diff --git a/docs/AimForOffer/TreeNode.java b/docs/AimForOffer/TreeNode.java new file mode 100644 index 0000000..c9297d8 --- /dev/null +++ b/docs/AimForOffer/TreeNode.java @@ -0,0 +1,9 @@ +/** + * Created by 18351 on 2019年7月23日. + */ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode(int x) { val = x; } +} diff --git "a/docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" "b/docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" new file mode 100644 index 0000000..7a2963c --- /dev/null +++ "b/docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" @@ -0,0 +1,31 @@ +import java.util.Scanner; + +/** + * Created by 18351 on 2019年7月23日. + */ +public class 二叉树的下一个结点_Important { + //二叉树的下一个结点 + public TreeLinkNode GetNext(TreeLinkNode pNode){ + if(pNode==null){ + return null; + } + if(pNode.right!=null){ + //先判断 pNode 的右子树不为 null, + //pNode 的下一个结点就是 pNode 右子树的最左结点 + TreeLinkNode node = pNode.right; //pNode 的右子树 + while(node.left!=null){ + node = node.left; + } + return node; + }else{ //否则,向上找第一个左连接指向的树包含该节点的祖先节点 + while (pNode.next!=null){ + TreeLinkNode parent = pNode.next; + if(parent.left==pNode){ + return parent; + } + pNode = pNode.next; + } + } + return null; + } +} diff --git "a/docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" "b/docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" new file mode 100644 index 0000000..ceaa998 --- /dev/null +++ "b/docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" @@ -0,0 +1,32 @@ +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by 18351 on 2019年7月24日. + */ +public class 变态跳台阶_Important { + //动态规划思路: + //dp[i] 表示跳 i 阶台阶共有 dp[i] 中跳法 + public int JumpFloorII(int target) { + int[] dp=new int[target+1]; + //dp 数组数值初始化为 1 + Arrays.fill(dp,1); + + for(int i=2;i<=target;i++){ + for(int j=1;jpreEnd || inStart>inEnd){ + return null; + } + TreeNode root = new TreeNode(pre[preStart]); + + int index = -1; + for(int i=inStart;i<=inend;i++){ + if(in[i]==pre[preStart]){ + index = i; + break; + } + } + root.left = reConstructBinaryTree(pre,in, + preStart+1,preStart+(index-inStart),inStart,index-1); + root.right = reConstructBinaryTree(pre,in, + preStart+(index-inStart)+1,preEnd,index+1,inEnd); + return root; + } +} diff --git "a/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" "b/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" index 3dd4684..54c4855 100644 --- "a/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" +++ "b/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" @@ -1,10 +1,7 @@ -import org.junit.Test; - /** - * Created by DHA on 2019/7/22. + * Created by 18351 on 2019/7/23. */ public class 数组中重复的数字 { - //数组中重复的数字 public boolean duplicate(int numbers[],int length,int [] duplication) { for(int i=0;iarray[i]){ + res = array[i]; + break; + } + } + return res; + } + + //二分查找的变形: + //关键在于确定旋转数组在那一部分 + public int minNumberInRotateArray(int [] array) { + if(array==null || array.length==0){ + return 0; + } + if(array.length==1){ + return array[0]; + } + + int l=0; + int h=array.length-1; + while(l=0 && P2>= P1){ + char ch = str.charAt(P1); + if(ch==' '){ + str.setCharAt(P2--,'0'); + str.setCharAt(P2--,'2'); + str.setCharAt(P2--,'%'); + }else{ + str.setCharAt(P2--,ch); + } + P1--; + } + return str.toString(); + } + + @Test + public void test(){ + StringBuffer buffer = new StringBuffer(); + buffer.append("A B C"); + System.out.println(replaceSpace(buffer).toString()); + } +} diff --git "a/docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" "b/docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" new file mode 100644 index 0000000..50a4694 --- /dev/null +++ "b/docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" @@ -0,0 +1,35 @@ +import java.util.Stack; + +/** + * Created by 18351 on 2019年7月23日. + */ +public class 用两个栈实现队列 { + //用两个栈实现队列 + Stack stack1 = new Stack(); + Stack stack2 = new Stack(); + int front; //用来记录第一个出栈元素 + + public void push(int node) { + if (stack1.isEmpty()){ + front = node; + } + stack1.push(node); + } + + public int pop() { + if(stack2.isEmpty()){ + while(!stack1.isEmpty()){ + stack2.push(stack1.pop()); + } + } + return stack2.pop(); + } + + public static void main(String[] args) { + 用两个栈实现队列 q = new 用两个栈实现队列(); + q.push(1); + q.push(2); + q.push(3); + q.pop(); + } +} diff --git "a/docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" "b/docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" new file mode 100644 index 0000000..45160bf --- /dev/null +++ "b/docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" @@ -0,0 +1,37 @@ +import org.junit.Test; + +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by 18351 on 2019年7月23日. + */ +public class 矩形覆盖_Important { + //思路: + //n=1 时,1 种 + //n=2 时,2 种 + //n=3 时,3 种 + //n=4 时,5 种 + //f(n) = f(n-1) + f(n-2) + //注意:时间复杂度 + //使用递归的方式时间复杂度较高 + public int RectCover(int target) { + if (target==1){ + return 1; + } + if(target==2){ + return 2; + } + + //TODO:循环方式替代递归方式 + int pre1 = 1; + int pre2 = 2; + int res = 0; + for(int i=3;i<=target;i++){ + res = pre1 + pre2; + pre1 = pre2; + pre2 = res; + } + return res; + } +} diff --git "a/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" "b/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" index 37c982c..86f084f 100644 --- "a/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" +++ "b/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" @@ -1,83 +1,6 @@ -import org.junit.Test; - /** - * Created by DHA on 2019/7/25. + * Created by 18351 on 2019/7/25. */ public class 矩阵中的路径 { - private int m,n; //矩阵的长度、宽度 - private boolean[][] visted; //标记是否访问 - - private int[][] d={ - {0,1}, //向右 - {-1,0},//向上 - {0,-1},//向左 - {1,0} //向下 - }; - - private boolean inArea(int x,int y){ - return (x>=0 && x=0 && y Date: 2019年8月20日 22:08:37 +0800 Subject: [PATCH 3/4] Java-Notes --- ...code-Database 351円242円230円350円247円243円.md" | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git "a/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" "b/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" index 4597546..7d731a2 100644 --- "a/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" +++ "b/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" @@ -284,7 +284,7 @@ HAVING COUNT(id)>= 2; # *6、删除重复的电子邮箱(196) -https://leetcode.com/problems/delete-duplicate-emails/description/ +[196. 删除重复的电子邮箱](https://leetcode-cn.com/problems/delete-duplicate-emails/) - 问题描述 @@ -356,7 +356,7 @@ WHERE # 7、组合两个表(175) -https://leetcode.com/problems/combine-two-tables/description/ +[175. 组合两个表](https://leetcode-cn.com/problems/combine-two-tables/) - 问题描述: @@ -434,7 +434,7 @@ ON p.PersonId=a.PersonId; # *8、超过经理收入的员工(181) -https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ +[181. 超过经理收入的员工](https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/) - 问题描述: @@ -504,7 +504,7 @@ FROM # 9、从不订购的客户(183) -https://leetcode.com/problems/customers-who-never-order/description/ +[181. 超过经理收入的员工](https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/) - 问题描述: @@ -591,7 +591,7 @@ WHERE # *10、部门工资最高的员工(184) -https://leetcode.com/problems/department-highest-salary/description/ +[184. 部门工资最高的员工](https://leetcode-cn.com/problems/department-highest-salary/) - 问题描述: @@ -682,7 +682,7 @@ WHERE # 11、第二高的薪水(176) -https://leetcode.com/problems/second-highest-salary/description/ +[176. 第二高的薪水](https://leetcode-cn.com/problems/second-highest-salary/) - 问题描述: @@ -767,7 +767,7 @@ END # 13、分数排名(178) -https://leetcode.com/problems/rank-scores/description/ +[177. 第N高的薪水](https://leetcode-cn.com/problems/nth-highest-salary/) - 问题描述: @@ -838,6 +838,8 @@ ORDER BY # *14、连续出现的数字(180) +[180. 连续出现的数字](https://leetcode-cn.com/problems/consecutive-numbers/) + - 问题描述: 数字表: @@ -884,9 +886,8 @@ VALUES ( 7, 2 ); ``` -- 解题 +- 解题: -- ```sql # 思路:要求是连续出现 3 次,可使用 3 张该表 @@ -930,7 +931,7 @@ WHERE L1.Num = L2.Num # 15、换座位(626)(了解) -https://leetcode.com/problems/exchange-seats/description/ +[626. 换座位](https://leetcode-cn.com/problems/exchange-seats/) - 问题描述: From 943332707dd9abf36e0a26369956e1ebe05815fd Mon Sep 17 00:00:00 2001 From: DuHouAn <18351926682@163.com> Date: 2019年8月21日 21:18:07 +0800 Subject: [PATCH 4/4] Java-Notes --- docs/AimForOffer/MyQueue.java | 56 ------------------ docs/AimForOffer/ThreadSafeLRUCache.java | 49 ---------------- docs/AimForOffer/TreeLinkNode.java | 13 ----- docs/AimForOffer/TreeNode.java | 9 --- ...52347円273円223円347円202円271円_Important.java" | 31 ---------- ...345円215円260円351円223円276円350円241円250円.java" | 32 ---------- ...63345円217円260円351円230円266円_Important.java" | 32 ---------- ...344円272円214円345円217円211円346円240円221円.java" | 30 ---------- ...347円232円204円346円225円260円345円255円227円.java" | 27 --------- ...17346円225円260円345円255円227円_Important.java" | 58 ------------------- ...42347円251円272円346円240円274円_Important.java" | 43 -------------- ...345円276円205円345円244円204円347円220円206円.java" | 37 ------------ ...347円247円257円346円225円260円347円273円204円.java" | 36 ------------ ...347円216円260円351円230円237円345円210円227円.java" | 35 ----------- ...42350円246円206円347円233円226円_Important.java" | 37 ------------ ...347円232円204円350円267円257円345円276円204円.java" | 6 -- ...350円267円263円345円217円260円351円230円266円.java" | 29 ---------- ...code-Database 351円242円230円350円247円243円.md" | 2 +- ...14345円233円236円346円272円257円346円263円225円.md" | 6 +- 19 files changed, 4 insertions(+), 564 deletions(-) delete mode 100644 docs/AimForOffer/MyQueue.java delete mode 100644 docs/AimForOffer/ThreadSafeLRUCache.java delete mode 100644 docs/AimForOffer/TreeLinkNode.java delete mode 100644 docs/AimForOffer/TreeNode.java delete mode 100644 "docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" delete mode 100644 "docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" delete mode 100644 "docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" delete mode 100644 "docs/AimForOffer/345円273円272円344円272円214円345円217円211円346円240円221円.java" delete mode 100644 "docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" delete mode 100644 "docs/AimForOffer/346円227円213円350円275円254円346円225円260円347円273円204円347円232円204円346円234円200円345円260円217円346円225円260円345円255円227円_Important.java" delete mode 100644 "docs/AimForOffer/346円233円277円346円215円242円347円251円272円346円240円274円_Important.java" delete mode 100644 "docs/AimForOffer/346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円_345円276円205円345円244円204円347円220円206円.java" delete mode 100644 "docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" delete mode 100644 "docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" delete mode 100644 "docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" delete mode 100644 "docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" delete mode 100644 "docs/AimForOffer/350円267円263円345円217円260円351円230円266円.java" diff --git a/docs/AimForOffer/MyQueue.java b/docs/AimForOffer/MyQueue.java deleted file mode 100644 index 59d933c..0000000 --- a/docs/AimForOffer/MyQueue.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.Stack; - -/** - * Created by 18351 on 2019年7月23日. - */ -//使用两个栈实现队列的扩展 -public class MyQueue { - //用两个栈实现队列 - Stack stack1 = new Stack(); - Stack stack2 = new Stack(); - - //存储队列头元素 - private int front; //方便后面的 peek() 操作 - - /** Initialize your data structure here. */ - public MyQueue() { - stack1 = new Stack(); - stack2 = new Stack(); - } - - public void push(int node) { - if(stack1.isEmpty()){ - front = node; - } - stack1.push(node); - } - - public int pop() { - if(stack2.isEmpty()){ - while(!stack1.isEmpty()){ - stack2.push(stack1.pop()); - } - } - return stack2.pop(); - } - - public int peek(){ - if(stack2.isEmpty()){ - return front; - } - return stack2.peek(); - } - - public boolean empty(){ - return (stack1.isEmpty()) && (stack2.isEmpty()); - } - - public static void main(String[] args) { - MyQueue queue = new MyQueue(); - queue.push(1); - queue.push(2); - System.out.println(queue.peek()); // 返回 1 - System.out.println(queue.pop()); // 返回 1 - queue.empty(); // 返回 false - } -} diff --git a/docs/AimForOffer/ThreadSafeLRUCache.java b/docs/AimForOffer/ThreadSafeLRUCache.java deleted file mode 100644 index b725030..0000000 --- a/docs/AimForOffer/ThreadSafeLRUCache.java +++ /dev/null @@ -1,49 +0,0 @@ -import org.junit.Test; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Created by 18351 on 2019年7月25日. - */ -public class ThreadSafeLRUCache { - private static final int MAX_CAPACITY = 3; - private LinkedHashMap linkedHashMap; - - public ThreadSafeLRUCache(){ - linkedHashMap = new LinkedHashMap(MAX_CAPACITY,0.75f,false){ - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size()>MAX_CAPACITY; - } - }; - } - - public synchronized void put(K k,V v){ - linkedHashMap.put(k,v); - } - - public synchronized V get(K k){ - return (V)linkedHashMap.get(k); - } - - @Override - public String toString() { - StringBuilder sb=new StringBuilder(); - for(Map.Entry entry:linkedHashMap.entrySet()) - sb.append(String.format("%s: %s\n", entry.getKey(), entry.getValue())); - return sb.toString(); - } - - @Test - public void test(){ - ThreadSafeLRUCache cache=new ThreadSafeLRUCache(); - cache.put(1, "a"); - cache.put(2, "b"); - cache.put(3, "c"); - cache.get(1); - //LRU 键值1被访问过了,则最近最久未访问的就是2 - cache.put(4, "d"); - System.out.println(cache); - } -} diff --git a/docs/AimForOffer/TreeLinkNode.java b/docs/AimForOffer/TreeLinkNode.java deleted file mode 100644 index c277e9e..0000000 --- a/docs/AimForOffer/TreeLinkNode.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Created by 18351 on 2019年7月23日. - */ -public class TreeLinkNode { - int val; - TreeLinkNode left = null; - TreeLinkNode right = null; - TreeLinkNode next = null; - - TreeLinkNode(int val) { - this.val = val; - } -} diff --git a/docs/AimForOffer/TreeNode.java b/docs/AimForOffer/TreeNode.java deleted file mode 100644 index c9297d8..0000000 --- a/docs/AimForOffer/TreeNode.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Created by 18351 on 2019年7月23日. - */ -public class TreeNode { - int val; - TreeNode left; - TreeNode right; - TreeNode(int x) { val = x; } -} diff --git "a/docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" "b/docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" deleted file mode 100644 index 7a2963c..0000000 --- "a/docs/AimForOffer/344円272円214円345円217円211円346円240円221円347円232円204円344円270円213円344円270円200円344円270円252円347円273円223円347円202円271円_Important.java" +++ /dev/null @@ -1,31 +0,0 @@ -import java.util.Scanner; - -/** - * Created by 18351 on 2019年7月23日. - */ -public class 二叉树的下一个结点_Important { - //二叉树的下一个结点 - public TreeLinkNode GetNext(TreeLinkNode pNode){ - if(pNode==null){ - return null; - } - if(pNode.right!=null){ - //先判断 pNode 的右子树不为 null, - //pNode 的下一个结点就是 pNode 右子树的最左结点 - TreeLinkNode node = pNode.right; //pNode 的右子树 - while(node.left!=null){ - node = node.left; - } - return node; - }else{ //否则,向上找第一个左连接指向的树包含该节点的祖先节点 - while (pNode.next!=null){ - TreeLinkNode parent = pNode.next; - if(parent.left==pNode){ - return parent; - } - pNode = pNode.next; - } - } - return null; - } -} diff --git "a/docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" "b/docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" deleted file mode 100644 index c73507b..0000000 --- "a/docs/AimForOffer/344円273円216円345円260円276円345円210円260円345円244円264円346円211円223円345円215円260円351円223円276円350円241円250円.java" +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.ArrayList; - -/** - * Created by DHA on 2019年7月22日. - */ -public class 从尾到头打印链表 { - //从尾到头打印链表 - public ArrayList printListFromTailToHead(ListNode listNode) { - ArrayList res = new ArrayList(); - - //逆置该链表 - ListNode head = reverse(listNode); - while(head!=null){ - res.add(head.val); - head = head.next; - } - return res; - } - - private ListNode reverse(ListNode listNode){ - ListNode pre = null; - ListNode cur = listNode; - while(cur!=null){ - ListNode next = cur.next; - cur.next = pre; - - pre = cur; - cur = next; - } - return pre; - } -} diff --git "a/docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" "b/docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" deleted file mode 100644 index ceaa998..0000000 --- "a/docs/AimForOffer/345円217円230円346円200円201円350円267円263円345円217円260円351円230円266円_Important.java" +++ /dev/null @@ -1,32 +0,0 @@ -import org.junit.Test; - -import java.util.Arrays; - -/** - * Created by 18351 on 2019年7月24日. - */ -public class 变态跳台阶_Important { - //动态规划思路: - //dp[i] 表示跳 i 阶台阶共有 dp[i] 中跳法 - public int JumpFloorII(int target) { - int[] dp=new int[target+1]; - //dp 数组数值初始化为 1 - Arrays.fill(dp,1); - - for(int i=2;i<=target;i++){ - for(int j=1;jpreEnd || inStart>inEnd){ - return null; - } - TreeNode root = new TreeNode(pre[preStart]); - - int index = -1; - for(int i=inStart;i<=inend;i++){ - if(in[i]==pre[preStart]){ - index = i; - break; - } - } - root.left = reConstructBinaryTree(pre,in, - preStart+1,preStart+(index-inStart),inStart,index-1); - root.right = reConstructBinaryTree(pre,in, - preStart+(index-inStart)+1,preEnd,index+1,inEnd); - return root; - } -} diff --git "a/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" "b/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" deleted file mode 100644 index 54c4855..0000000 --- "a/docs/AimForOffer/346円225円260円347円273円204円344円270円255円351円207円215円345円244円215円347円232円204円346円225円260円345円255円227円.java" +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Created by 18351 on 2019/7/23. - */ -public class 数组中重复的数字 { - public boolean duplicate(int numbers[],int length,int [] duplication) { - for(int i=0;iarray[i]){ - res = array[i]; - break; - } - } - return res; - } - - //二分查找的变形: - //关键在于确定旋转数组在那一部分 - public int minNumberInRotateArray(int [] array) { - if(array==null || array.length==0){ - return 0; - } - if(array.length==1){ - return array[0]; - } - - int l=0; - int h=array.length-1; - while(l=0 && P2>= P1){ - char ch = str.charAt(P1); - if(ch==' '){ - str.setCharAt(P2--,'0'); - str.setCharAt(P2--,'2'); - str.setCharAt(P2--,'%'); - }else{ - str.setCharAt(P2--,ch); - } - P1--; - } - return str.toString(); - } - - @Test - public void test(){ - StringBuffer buffer = new StringBuffer(); - buffer.append("A B C"); - System.out.println(replaceSpace(buffer).toString()); - } -} diff --git "a/docs/AimForOffer/346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円_345円276円205円345円244円204円347円220円206円.java" "b/docs/AimForOffer/346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円_345円276円205円345円244円204円347円220円206円.java" deleted file mode 100644 index ada8700..0000000 --- "a/docs/AimForOffer/346円234円272円345円231円250円344円272円272円347円232円204円350円277円220円345円212円250円350円214円203円345円233円264円_345円276円205円345円244円204円347円220円206円.java" +++ /dev/null @@ -1,37 +0,0 @@ -import org.junit.Test; - -/** - * Created by DHA on 2019年7月25日. - */ -public class 机器人的运动范围 { - private int m,n; - - private int[][] d={ - {0,1}, //向右 - {-1,0},//向上 - {0,-1},//向左 - {1,0} //向下 - }; - - //获取一个数各个位上的数字相加 - private int getNum(int num){ - int sum = 0; - while(num>0){ - sum += num %10; - num/=10; - } - return sum; - } - - - - public int movingCount(int threshold, int rows, int cols) { - - } - - @Test - public void test(){ - int num = 37; - System.out.println(getNum(num)); - } -} diff --git "a/docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" "b/docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" deleted file mode 100644 index bb5acd5..0000000 --- "a/docs/AimForOffer/346円236円204円345円273円272円344円271円230円347円247円257円346円225円260円347円273円204円.java" +++ /dev/null @@ -1,36 +0,0 @@ -import org.junit.Test; - -/** - * Created by DHA on 2019年7月22日. - */ -public class 构建乘积数组 { - //构建乘积数组 - //思路: - //B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。 - //B[i] 可拆分成 (A[0]*A[1]*...*A[i-1])*(A[i+1]*...*A[n-1])两部分 - public int[] multiply(int[] A) { - int n = A.length; - int[] B = new int[n]; - - //B[i] = A[0]*A[1]*...*A[i-1] - int product =1; - for(int i=0;i=0;product*=A[i],i--){ - B[i]*= product; - } - return B; - } - - @Test - public void test(){ - int[] A={1,2,3,4,5}; - int[] B=multiply(A); - for(int num:B){ - System.out.println(num); - } - } -} diff --git "a/docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" "b/docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" deleted file mode 100644 index 50a4694..0000000 --- "a/docs/AimForOffer/347円224円250円344円270円244円344円270円252円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.java" +++ /dev/null @@ -1,35 +0,0 @@ -import java.util.Stack; - -/** - * Created by 18351 on 2019年7月23日. - */ -public class 用两个栈实现队列 { - //用两个栈实现队列 - Stack stack1 = new Stack(); - Stack stack2 = new Stack(); - int front; //用来记录第一个出栈元素 - - public void push(int node) { - if (stack1.isEmpty()){ - front = node; - } - stack1.push(node); - } - - public int pop() { - if(stack2.isEmpty()){ - while(!stack1.isEmpty()){ - stack2.push(stack1.pop()); - } - } - return stack2.pop(); - } - - public static void main(String[] args) { - 用两个栈实现队列 q = new 用两个栈实现队列(); - q.push(1); - q.push(2); - q.push(3); - q.pop(); - } -} diff --git "a/docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" "b/docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" deleted file mode 100644 index 45160bf..0000000 --- "a/docs/AimForOffer/347円237円251円345円275円242円350円246円206円347円233円226円_Important.java" +++ /dev/null @@ -1,37 +0,0 @@ -import org.junit.Test; - -import java.util.WeakHashMap; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Created by 18351 on 2019年7月23日. - */ -public class 矩形覆盖_Important { - //思路: - //n=1 时,1 种 - //n=2 时,2 种 - //n=3 时,3 种 - //n=4 时,5 种 - //f(n) = f(n-1) + f(n-2) - //注意:时间复杂度 - //使用递归的方式时间复杂度较高 - public int RectCover(int target) { - if (target==1){ - return 1; - } - if(target==2){ - return 2; - } - - //TODO:循环方式替代递归方式 - int pre1 = 1; - int pre2 = 2; - int res = 0; - for(int i=3;i<=target;i++){ - res = pre1 + pre2; - pre1 = pre2; - pre2 = res; - } - return res; - } -} diff --git "a/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" "b/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" deleted file mode 100644 index 86f084f..0000000 --- "a/docs/AimForOffer/347円237円251円351円230円265円344円270円255円347円232円204円350円267円257円345円276円204円.java" +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Created by 18351 on 2019/7/25. - */ -public class 矩阵中的路径 { - -} diff --git "a/docs/AimForOffer/350円267円263円345円217円260円351円230円266円.java" "b/docs/AimForOffer/350円267円263円345円217円260円351円230円266円.java" deleted file mode 100644 index 4761874..0000000 --- "a/docs/AimForOffer/350円267円263円345円217円260円351円230円266円.java" +++ /dev/null @@ -1,29 +0,0 @@ -import org.junit.Test; - -/** - * Created by 18351 on 2019/7/24. - */ -public class 跳台阶 { - //思路:target 是指 n 节级台阶 - //n = 1, 有 1 种跳法 - //n = 2, 有 2 种跳法 - //n = 3, 有 3 种跳法 - public int JumpFloor(int target) { - if(target<=2){ - return target; - } - int pre1 = 1; - int pre2 = 2; - for(int i=3;i<=target;i++){ - int next = pre1 + pre2; - pre1 = pre2; - pre2 = next; - } - return pre2; - } - - @Test - public void test(){ - System.out.println(JumpFloor(5)); - } -} diff --git "a/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" "b/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" index 7d731a2..c3d52b5 100644 --- "a/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" +++ "b/docs/DataBase/09Leetcode-Database 351円242円230円350円247円243円.md" @@ -767,7 +767,7 @@ END # 13、分数排名(178) -[177. 第N高的薪水](https://leetcode-cn.com/problems/nth-highest-salary/) +[178. 分数排名](https://leetcode-cn.com/problems/rank-scores/) - 问题描述: diff --git "a/docs/LeetCode/06351円200円222円345円275円222円345円222円214円345円233円236円346円272円257円346円263円225円.md" "b/docs/LeetCode/06351円200円222円345円275円222円345円222円214円345円233円236円346円272円257円346円263円225円.md" index 676d5f8..c47219a 100644 --- "a/docs/LeetCode/06351円200円222円345円275円222円345円222円214円345円233円236円346円272円257円346円263円225円.md" +++ "b/docs/LeetCode/06351円200円222円345円275円222円345円222円214円345円233円236円346円272円257円346円263円225円.md" @@ -43,7 +43,7 @@ s(digits)是digits所能代表的字母字符串 letter(digits[i])是digits[i]所能代表的字母 s(digits[0...n-1]) - + = letter(digits[0]) + s(digits[1...n-1]) = letter(digits[0]) + letter(digits[1]) + s(digits[2...n-1]) @@ -365,7 +365,7 @@ Explanation: The graph looks like this: 这里面graph是使用的二维数组表示的,[[1,2], [3], [3], []]可以使用矩阵这样表示 - + ```java private List> res; /** @@ -1719,5 +1719,5 @@ private boolean canPartition(int[] nums,int[] sums,int k,int index,int target){ return false; } ``` - + ## 其他递归问题 \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /