![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
文章平均质量分 94
mudamu88
这个作者很懒,什么都没留下…
展开
-
Springboot和Angular的CSRF防御
CSRF 是什么跨站请求伪造知乎解答搬运: csrf是什么.Springboot CSRFAngular CSRFAngular官方文档: cross-site-request-forgery.在跨站请求伪造(XSRF 或 CSFR)中,攻击者欺骗用户,让他们访问一个假冒页面(例如 evil.com), 该页面带有恶意代码,秘密的向你的应用程序服务器发送恶意请求(例如 example-bank.com)。假设用户已经在 example-bank.com 登录。用户打开一个邮件,点击里面的链接,原创 2021-09-07 20:58:25 · 1317 阅读 · 2 评论 -
278. First Bad Version
第一个错误版本 思路:二分法 You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is devel...原创 2018-04-21 11:53:32 · 116 阅读 · 0 评论 -
226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1**反转二叉树 方法一**:引入一个队列进行层序遍历(leetcode时间超过20%的提交)/** * Definition ...原创 2018-04-13 20:43:51 · 108 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 题意:找出二叉树的最小深度。/** * Definition for a ...原创 2018-04-13 19:26:19 · 90 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.For example: Given binary tree [3,9,2...原创 2018-04-13 17:46:36 · 134 阅读 · 0 评论 -
617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree...原创 2018-04-13 15:55:19 · 123 阅读 · 0 评论 -
669. Trim a Binary Search Tree
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the re...原创 2018-04-13 15:49:33 · 134 阅读 · 0 评论 -
637 Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11] Exp...原创 2018-04-13 15:43:52 · 136 阅读 · 0 评论 -
排序算法模板(java)
1 快速排序public class Solution { public void sort(int[] nums){ if (nums == null || nums.length == 0) return; quickSort(nums, 0, nums.legnth-1) } private void quickSort(in...原创 2018-04-23 09:39:40 · 489 阅读 · 0 评论 -
242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false. Note: You may assume ...原创 2018-04-22 23:48:32 · 118 阅读 · 0 评论 -
162. Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its index. The array may contain multiple peaks, in that...原创 2018-04-21 23:17:08 · 153 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array(java)
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Coul原创 2017-08-23 23:15:21 · 363 阅读 · 0 评论 -
119. Pascal's Triangle II待续。。。
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?这道题跟Pascal's原创 2017-08-05 23:16:39 · 177 阅读 · 0 评论 -
189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note: Try to come up as many solutions as you can,...原创 2018-04-21 13:39:15 · 121 阅读 · 0 评论 -
153. Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicat...原创 2018-04-21 15:41:30 · 141 阅读 · 0 评论 -
240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in ea...原创 2018-04-21 16:25:47 · 104 阅读 · 0 评论 -
Springboot实现多线程注入bean的工具类
场景: 使用springboot多线程,线程类无法自动注入需要的bean,解决方法: 通过工具类获取需要的bean工具类代码:import org.springframework.beans.BeansException;import org.springframework.context.ApplicationContext;import org.springframework.con...原创 2018-12-10 14:17:47 · 2822 阅读 · 0 评论 -
罗马数字转阿拉伯数字
public class Main { public static void main(String[] args) { System.out.println("Hello World!"); } public static int transfer(String roma){ //建立一个符号与value对应的数组 int...原创 2018-10-16 12:03:58 · 291 阅读 · 0 评论 -
二叉树遍历(递归、BFS、DFS)
import java.util.LinkedList;import java.util.Queue;// 0// / \// 1 2// / \// 3 4public class maxDepth{ public static void main(String[] args){ ...原创 2018-09-05 21:20:52 · 649 阅读 · 0 评论 -
0-1背包问题
问题描述:现有n件物品和一个容量为c的背包。第i件物品的重量是重量为w[i],价值是v[i]。已知对于一件物品必须选择取(用1表示)或者不取(用0表示),且每件物品只能被取一次(这就是“0-1”的含义)。求放置哪些物品进背包,可使这些物品的重量总和不超过背包容量,且价值总和最大。求解思路:假设有5件物品,其重量分别是w={2,2,6,5,4},价值分别是v={6,3,5,4,6},背...原创 2018-08-29 13:43:38 · 246 阅读 · 0 评论 -
215. Kth Largest Element in an Array数组中的第K个最大元素
数组中的第K个最大元素 使用PriorityQueueimport java.util.PriorityQueue;class Solution { public int findKthLargest(int[] nums, int k) { PriorityQueue<Integer> queue = new PriorityQueue<>...原创 2018-08-28 21:50:53 · 168 阅读 · 0 评论 -
LeetCode23. 合并K个排序链表
合并K个排序链表 public static ListNode mergeKListNode(List<ListNode> list){ PriorityQueue<ListNode> queue = new PriorityQueue<>(Comparator.comparing(node -> node.val)); ...原创 2018-08-28 21:34:31 · 326 阅读 · 0 评论 -
Java多线程通信:交替打印ABAB
使用wait()和notify()实现Java多线程通信:两个线程交替打印A和B,如ABABABpublic class Test { public static void main(String[] args) { final PrintAB print = new PrintAB(); new Thread(new Runnable() { ...原创 2018-08-20 16:35:38 · 6505 阅读 · 1 评论 -
Mybatis基本使用
1 mysql数据库操作 SQL脚本:create database mybatis;use mybatis;CREATE TABLE tb_user ( ID INT(11) PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR (18) DEFAULT NULL, SEX CHAR (2) DEFAULT NULL, AGE INT(11)...原创 2018-07-25 11:12:59 · 265 阅读 · 0 评论 -
MySQL Java 编程Demo
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class MysqlDemo { public static void main(Str...原创 2018-07-25 10:53:31 · 714 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found ...原创 2018-04-21 22:24:57 · 553 阅读 · 0 评论 -
69. Sqrt(x)
Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-negative integer Since the return type is an integer, the decimal digits are truncated and only ...原创 2018-04-21 21:18:34 · 134 阅读 · 0 评论 -
74. Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each r...原创 2018-04-21 17:04:31 · 143 阅读 · 0 评论 -
118. Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]每一行cur都是前一行pre生成出来的,原创 2017-08-05 22:23:47 · 200 阅读 · 0 评论 -
485. Max Consecutive Ones
给定数组,求最大的连续1的个数。思路:遍历数组,用一个计数器tmp来统计1的个数,如果当前数字为0,那么tmp重置为0,如果是1,tmp自增1,然后每次更新结果max。原创 2017-08-05 21:11:15 · 167 阅读 · 0 评论 -
27. Remove Element(java)
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2017-08-02 21:34:19 · 248 阅读 · 0 评论 -
66. Plus One(java)
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digi原创 2017-08-02 20:14:17 · 396 阅读 · 0 评论 -
142. Linked List Cycle II(java)
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.public class Solution { public ListNode detectCycle(ListNod原创 2017-07-25 15:16:17 · 253 阅读 · 0 评论 -
141. Linked List Cycle(java)
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?给定一个链表,判断它是否有环。思路:使用快慢引用的思路。两个指针fast、slow都指向head,从head开始遍历,fast每次走两步,slow每次前走一步。如果链表有环,那么进入环...原创 2017-07-25 11:48:00 · 307 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List(java)
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.给定链表,删除所有重复,使得每个元素只出现一次原创 2017-07-25 00:54:36 · 232 阅读 · 0 评论 -
203. Remove Linked List Elements(Java)
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5删除单链表中所有数据域为给定val的节点:pub原创 2017-07-25 00:21:27 · 222 阅读 · 0 评论 -
53. Maximum Subarray(java)
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] ha原创 2017-08-01 22:56:25 · 576 阅读 · 0 评论 -
232. Implement Queue using Stacks(java)
用栈实现队列在进队列的时候,把栈s1逆序压入另一个辅助栈s2,再逆序入s1;出队列的时候直接出栈s1。原创 2017-08-01 20:05:53 · 427 阅读 · 0 评论 -
225. Implement Stack using Queues(java)
用两个队列q1,q2实现一个栈。push时把新元素添加到q1的队尾。pop时把q1中除最后一个元素外逐个添加到q2中,然后pop掉q1中的最后一个元素,然后交换q1和q2,以保证添加元素时始终向q1中添加。原创 2017-08-01 21:22:08 · 264 阅读 · 0 评论 -
496. Next Greater Element I
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums原创 2017-08-01 16:25:12 · 232 阅读 · 0 评论