- 博客(35)
- 资源 (3)
- 收藏
- 关注
原创 简单实现一个死锁Java
class lock1 implements Runnable{ public void run(){ synchronized(Main.l1){ System.out.println("1:我获得了第一个锁"); try { Thread.sleep(3000); } catch (InterruptedEx...
2018-04-23 14:58:56 3544 3
原创 生产者/消费者问题的实现(JAVA)
1.阻塞队列class producer implements Runnable{ private final BlockingQueue sharedQueue; public producer(BlockingQueue sharedQueue){ this.sharedQueue=sharedQueue; } public void run()...
2018-04-23 14:51:45 216
原创 能放进hashmap的一个自定义类
public class HashTest{ private int i; public getInt(){ return i; } public void setI(int i){ this.i=i; } public boolean equals(Object object){ if(object=...
2018-04-21 12:13:25 775
原创 自定义comparator使用方法
升序import java.util.Arrays; import java.util.Comparator; public class Main { public static void main (String[] args) { Integer a[]={5,4,3,2,1}; Arrays.sort(a, new Co...
2018-04-20 15:12:08 1185
转载 最小的k个数(快速排序)
public ArrayList<Integer> GetLeastNumbers_Solution(int[] nums, int k) { if (k > nums.length || k <= 0) return new ArrayList<>(); int kthSmallest = findKthSmallest(nums, k - 1...
2018-04-20 13:59:23 483
原创 最小的k个数(堆实现)
用一个长度为K大根堆来维护这个最小的k个数。如果一个数比大根堆的堆顶小,说明它在最小的k个数里面。可以用Java的优先队列(底层是堆)设定优先级来实现! public ArrayList<Integer> GetLeastNumbers_Solution(int [] nums, int k) { if (k > nums.length || k <= 0)...
2018-04-20 13:45:32 550
原创 LeetCode 26. Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifying...
2018-04-18 13:18:26 160
原创 单例模式 (七种实现)
一、饿汉式O(线程安全):class MyObject{ private static MyObject object=new MyObject(); public static MyObject getobject(){ return object; }}二、懒汉式(线程不安全)class MyObject{ private static MyO...
2018-04-18 12:30:48 266
原创 排序算法Java实现
选择排序(升序): public static void sort(int[] a){ int N=a.length; for(int i=0;i<N;i++) { int min=i; for(int j=i+1;j<N;j++) { ...
2018-04-18 10:38:28 121
转载 网易nk数对
转载自https://blog.csdn.net/anlian523/article/details/79763170写的不错 我太菜了 哎一直都看不懂!题目描述:牛牛以前在老师那里得到了一个正整数数对(x, y), 牛牛忘记他们具体是多少了。但是牛牛记得老师告诉过他x和y均不大于n, 并且x除以y的余数大于等于k。牛牛希望你能帮他计算一共有多少个可能的数对。首先用两个for循环来暴力求解是可以得...
2018-04-16 22:42:21 222
原创 NIO利用通道来进行数据传输
/* * 一、通道:用于源节点与目标节点的连接.在Java NIO中负责缓冲区中的数据的传输。 * Channel本身不存储数据,需要配合缓冲区进行传输. * * 二、通道的主要实现类 * java.nio.channels.Channel接口: * FileChannel * //下面是用于网络的 * SocketChannel ...
2018-04-16 15:29:21 364
原创 LeetCode 数据库 175. Combine Two Tables
Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Perso...
2018-04-16 12:53:11 192 1
原创 LeetCode 28. Implement strStr() Java
水题Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Inpu...
2018-04-15 19:05:48 334
原创 初始NIO
/* * 1.缓冲区(Buffer):在Java NIO中负责数据的存取。缓冲区就是数组。 * 用于存储不同数据类型的数据 * * 根据数据类型不同(boolean 除外),提供了相应类型的缓冲区: * ByteBuffer * CharBuffer * ShortBuffer * IntBuffer * LongBuffer * FloatBuffer * DoubleB...
2018-04-14 21:42:18 100
原创 LeetCode 24. Swap Nodes in Pairs Java写法
Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only constant...
2018-04-14 19:53:36 132
原创 mysql定时任务
查看定时任务是否开启:show variables like 'event_scheduler';开启定时任务:set global event_scheduler = on;定时更新ON COMPLETION [NOT] PRESERVE :表示当事件不会再发生的情况下,删除事件(注意特定时间执行的事件,如果设置了该参数,执行完毕后,事件将被删除,不想删除的话可以设置成ON COMPLETION...
2018-04-14 19:05:20 191
原创 大话同步IO,异步IO,阻塞IO,非阻塞IO区别
最近在刷题,看到这个问题,可能说的有错,但是轻喷!首先一个IO操作其实分成了两个步骤:发起IO请求和实际的IO操作,阻塞IO和非阻塞IO的区别在于第一步是否会阻塞!同步IO和异步IO的区别在于第二步!如果实际的IO读写阻塞请求进程,那么就是同步IO,因此阻塞IO、非阻塞IO、IO复用、信号驱动IO都是同步IO,如果不阻塞,而是操作系统帮你做完IO操作再将结果返回给你,那么就是异步IO。所以阻塞和非...
2018-04-14 16:24:00 208 3
转载 请写出你最常见到的5个runtime exception
RuntimeException是java中所有运行时异常的父类,实际运行时出现的都是它的子类,看看RuntimeException的Java doc就可以随便列出几个:1,Object x = new Integer(0); System.out.println((String)x);当试图将对象强制转换为不是实例的子类时,抛出该异常(ClassCastException)...
2018-04-13 13:04:35 1205
原创 LeetCode 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个已排序的链表成一个排序链表(使用优先队列)class Solution { public ListNode mergeKLists(ListNode[] lists) { ...
2018-04-13 10:23:24 133
原创 Java优先队列使用
1,根据年龄小的先出优先级class Person implements Comparable<Person>{ public int age; Person(int age){ this.age=age; } public int compareTo(Person other){ return age-o...
2018-04-13 10:04:06 8308 1
原创 LeetCode 22. Generate Parentheses JAVA
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "...
2018-04-11 11:06:09 132
原创 LeetCode 19. Remove Nth Node From End of List JAVA删除链表倒数第N个
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the en...
2018-04-10 19:37:45 109
原创 LeetCode18. 4Sum Java
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set m...
2018-04-10 00:17:17 279
转载 Java模拟并发访问
public class ConcurrentTest { public static void main(String[] args) { ExecutorService exec = Executors.newFixedThreadPool(30); for (int index = 0; index < 1000000; index++) { fin
2018-04-08 18:57:26 210
原创 LeetCode 17. Letter Combinations of a Phone Number IN JAVA
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"...
2018-04-08 18:11:17 109
原创 mysql知识点
事务:1、属性:ACID原子性(Atomicity):事务是一个原子操作单元,其对数据的修改,要么全都执行,要么全都不执行。一致性(Consistent):在事务开始和完成时,数据都必须保持一致状态。这意味着所有相关的数据规则都必须应用于事务的修改,以保持数据的完整性;事务结束时,所有的内部数据结构(如B树索引或双向链表)也都必须是正确的。隔离性(Isolation):数据库系
2018-04-08 12:50:30 112
原创 mysql正则表达式学习
1,匹配任意一个字符SELECT prood_nameFROM productsWHERE pro_name REGEXP '.000'ORDER BY prod_name;返回 'csdn 5000' 'csdn 6000'这里使用了正则表达式.000。.是正则表达式一个字符,它表示匹配任意一个字符,因此,5000,6000都匹配且返回2,进行OR匹配SELECT prood_nameF...
2018-04-08 12:45:42 247
转载 正则表达式 匹配常用手机号
^1[3578]\d{9}$^1表示以1开头,[3578]表示第二位的数字为3578中的任意一个,\d{9}表示0~9范围内的数字匹配九次,$表示结束,12位以上的数字不匹配。
2018-04-07 21:59:05 946 1
转载 LeetCode-Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the following number...
2018-04-07 20:51:27 120
原创 LeetCode 16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly...
2018-04-07 16:44:31 98
原创 LeetCode 15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain dupli...
2018-04-07 16:23:25 77
原创 leetcode 10. Regular Expression Matching
这是剑指offer的一道题。Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the ent...
2018-04-06 17:20:08 92
转载 Java处理大数
在JAVA中有两个类BigInteger和BigDecimal分别表示大整数类和大浮点数类,理论上能够表示无限大的数,只要计算机内存足够大。这两个类都在java.math.*包中,因此每次必须在开头处引用该包。Ⅰ基本函数:1.valueOf(parament); 将参数转换为制定的类型比如 int a=3;BigInteger b=BigInteger.valueOf(a);则b=3;String...
2018-04-05 20:39:32 326
原创 LeetCode 6 ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I G...
2018-04-05 15:41:53 94
原创 leetcode 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2...
2018-04-05 14:36:47 116
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人