- 博客(13)
- 收藏
- 关注
原创 栈的压入
import java.util.ArrayList; import java.util.Stack; public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { if(pushA.length==0||popA.length==0||pushA.length!=popA.lengt...
2020-04-27 13:35:14 106
原创 棒球比赛
class Solution { public int calPoints(String[] ops) { Stack<Integer> stack = new Stack(); for(String s : ops) { if (s.equals("+")) { int top = st...
2020-04-27 13:34:23 66
原创 比较含退格的字符
class Solution { public boolean backspaceCompare(String S, String T) { Stack<Character> stack = new Stack(); Stack<Character> stack1 = new Stack(); for(char c: ...
2020-04-27 13:33:14 142
原创 股票价格跨度
class StockSpanner { private List<Integer> list; private List<Integer> rests; public StockSpanner() { list = new ArrayList<>(); rests = new ArrayList<>(); } public ...
2020-04-24 18:11:07 116
原创 插入排序/希尔排序/堆排序/冒泡排序
package Test0407; import java.util.Arrays; public class TestSort0409 { public static void insertSort(int[] array){//插入排序 //通过bound 来划分出两个区间 //[0,bound)已排序区间 //[bound,size...
2020-04-11 14:20:02 54
原创 最后一块石头的重量
class Solution { public int lastStoneWeight(int[] stones) { if(stones.length == 1) return stones[0]; int index = stones.length - 1; //每次操作最大数的下标 Arrays.so...
2020-04-11 14:07:43 136
原创 优先队列实现
package Test0407; public class MyPriorityQueue {//优先队列 //array 其实应该是堆 private int[] array = new int[100]; private int size = 0; public void offer(int x){//入队列 array[size] = x...
2020-04-08 15:43:11 96
原创 二叉树遍历
package Test0331; class Node{ public char val; public Node left; public Node right; public Node(char val) { this.val = val; } } public class TestTree { public static ...
2020-04-08 15:41:43 51
原创 找到小镇的法官
class Solution { public int findJudge(int N, int[][] trust) { int[] cnt = new int[N+1];//统计出入度 for (int[] index : trust) {//记录数组中出现的每个人的出入度 cnt[index[0]]--;//出度-- ...
2020-04-08 15:38:02 72
原创 设计单向链表的实现
public class ListNode{//设计单向链表的实现 int val; ListNode next; ListNode(int x){ val = x; } } class MyLinkedList { int size; ListNode head; /** Initialize your data stru...
2020-04-08 15:18:24 193
原创 将数组分成相等的三个部分
class Solution { public boolean canThreePartsEqualSum(int[] A) {//将数组分成相等的三个部分 int sum = 0; for(int i: A){ sum += i; } if(sum%3!=0){ return ...
2020-04-08 14:54:51 117
原创 判断二叉树是否是完全二叉树
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { publ...
2020-04-04 19:36:53 137
原创 二叉树基本概念总结
1.掌握树的基本概念 树:是一类重要的非线性数据结构,是以分支关系定义的层次结构。每个结点有零个或多个子结点;没有父结点的结点称为根结点;每一个非根结点有且只有一个父结点;除了根结点外,每个子结点可以分为多个不相交的子树 2. 掌握树的相关概念 节点的度:一个节点含有的子树的个数称为该节点的度; 如上图:A的为6 叶节点或终端节点:度为0的节点称为叶节点; 如上图:B、C、H、I…等节点为叶节点 ...
2020-04-04 19:09:12 169
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人