自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 算法系列------猜数字

小A 和 小B 在玩猜数字。小B 每次从 1, 2, 3 中随机选择一个,小A 每次也从 1, 2, 3 中选择一个猜。他们一共进行三次这个游戏,请返回 小A 猜对了几次?输入的guess数组为 小A 每次的猜测,answer数组为 小B 每次的选择。guess和answer的长度都等于3。class Solution { public int game(int[] guess, in...

2019-10-31 22:29:54 172

原创 算法系列------N叉数前序遍历

给定一个 N 叉树,返回其节点值的前序遍历。例如,给定一个 3叉树 :返回其前序遍历: [1,3,5,6,2,4]。/*// Definition for a Node.class Node { public int val; public List<Node> children; public Node() {} public Node...

2019-10-29 22:01:40 131

原创 算法系列------回文数

class Solution { public boolean isPalindrome(int x) { int j=0; if(x<0) return false; String xStr = x + ""; String yStr = reverse1(xStr); char...

2019-10-28 05:54:58 105

原创 算法系列------两数之和

给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer,Integer...

2019-10-27 16:05:35 106

原创 算法系列------二叉树的中序遍历

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { publ...

2019-10-18 19:53:00 117

原创 算法系列------二叉树的前序遍历

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public List<Integer> preorderTraversal(TreeNode root)

2019-10-17 22:11:02 82

原创 算法系列------验证回文串

class Solution { public boolean isPalindrome(String s) { if (s == null) return true; s = s.toLowerCase(); int l = s.length(); StringBuilder str = new StringBuilder(l); for (char c : s.toCharArray()) {

2019-10-16 19:55:36 80

原创 算法系列------用队列实现栈

class MyStack { private Queue<Integer> a;//输入队列 private Queue<Integer> b;//输出队列 public MyStack() { a = new LinkedList<>(); b = new LinkedList<>(); } public void push(int x) { a.o

2019-10-15 21:47:11 98

原创 算法系列------利用栈实现队列

class MyQueue { private Stack<Integer> a;// 输入栈 private Stack<Integer> b;// 输出栈 public MyQueue() { a = new Stack<>(); b = new Stack<>(); } public void push(int x) { a.push(x);

2019-10-14 22:02:11 108

原创 算法系列------括号匹配算法

public static Boolean isV(String s){ Stack<Character> stack = new Stack<>(); for(int i=0;i<s.length();i++){ if(s.charAt(i)=='{' || s.charAt(i)=='['|| s.charAt(i)=='('){ stack...

2019-10-13 20:17:27 106

原创 算法系列------队列

// 用数组实现的队列public class ArrayQueue { // 数组:items,数组大小:n private String[] items; private int n = 0; // head 表示队头下标,tail 表示队尾下标 private int head = 0; private int tail = 0; // 申请一个大小为 cap...

2019-10-12 21:10:03 77

原创 算法系列------手写栈

class ArrayStack { private long[] a; private int size; //栈数组的大小 private int top; //栈顶 public ArrayStack(int maxSize) { this.size = maxSize; this.a = new long[size]; ...

2019-10-11 18:18:33 136

原创 算法系列------链表是否有环

/*** * 用快慢指针判断链表是否有环 * @param head * @return */public boolean isCircleLinkedListNode(ListNode head){ if(head == null){ return false; } ListNode slow = head,fast = head; if...

2019-10-10 20:58:28 79

原创 算法系列------反转链表2

反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。说明:1 ≤ m ≤ n ≤ 链表长度。示例:输入: 1->2->3->4->5->NULL, m = 2, n = 4输出: 1->4->3->2->5->NULL/** * Definition for singly-linked list. * public c...

2019-10-09 21:20:48 73

原创 算法系列------合并两个有序链表

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode mergeTwoLis...

2019-10-08 22:12:50 73

原创 算法系列------反转链表

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode reverseList...

2019-10-07 21:14:47 74

原创 算法系列------单链表

public class LinkedList<E> { // 头节点 private Node top; // 链表长度 private int size; // 添加方法 public void add(E e) { Node newNode = new Node(); newNode.content = e; if (top == null) { ...

2019-10-06 22:50:44 69

原创 算法系列------快速排序

快速排序Public class QuickSort implements IArraySort { @Override public int[] sort(int[] sourceArray) throws Exception { // 对 arr 进行拷贝,不改变参数内容 int[] arr = Arrays.copyOf(sourceArr...

2019-10-05 21:05:17 213

原创 算法系列------插入排序

public int[] insertSort(int[] arr){ int n = arr.length; for(int i=1; i<n-1;i++){ // 记录要插入的数据 int tmp = arr[i]; // 从已经排序的序列最右边的开始比较,找到比其小的数 int j = i; ...

2019-10-04 22:37:05 60

原创 算法系列------选择排序

时间复杂度O(n²)原理选择排序public int[] selectSort(int[] arr) { //使用变量n存放集合长度 int n = arr.length; //遍历 for(int i=0; i<n-1; i++) { //纪录最小值下标位置 int min = i; for(int j=i+1; j<n;j++) { //通过比较...

2019-10-03 17:56:38 64

原创 算法系列------冒泡排序

这是我第一个知道的算法!冒泡排序public int[] bubbleShort(int[] arr) { for(int i=0; i<arr.length-1; i++) { for(int j=0; j<arr.length-1;j++) { if(arr[j]>arr[j+1]) { int temp = arr[j]; arr[j] = ...

2019-10-02 22:01:45 83

原创 算法系列------序(1)

时间复杂度和空间复杂度算法追求“快”和“省”,而“快”就是时间复杂度,“省”就是空间复杂度。用大O表示复杂度数据结构数据结构的含义1 代表了储存数据的集合2 代表了储存数据之间的特定关系8种数据结构初阶数据结构(4种)数组(Array)链表(Linked list)堆栈(Stack)队列(Queue)共同的名字线性表高阶数据结构(4种)树(Tree)集(Set)...

2019-10-01 22:10:51 92

空空如也

空空如也

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

TA关注的人

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