最近在做一个项目, 需要用到log4j来生成日志, 方便debug
但是log4j是分版本的, 现在的最新版是log4j2, 而不是log4j.
我一开始以为只是版本新旧有不同, 后来发现配置文件log4j.properties怎么都加载不进去. 查了好多资料才发现log4j2和log4j是不兼容的.
最近在做一个项目, 需要用到log4j来生成日志, 方便debug
但是log4j是分版本的, 现在的最新版是log4j2, 而不是log4j.
我一开始以为只是版本新旧有不同, 后来发现配置文件log4j.properties怎么都加载不进去. 查了好多资料才发现log4j2和log4j是不兼容的.
这是我读的第1个源码, mark一下吧.
强烈推荐 JDK8 HashMap源码行级解析 红黑树操作 史上最全最详细图解_anlian523的博客-CSDN博客. 关于红黑树的部分讲解的很好.
建议如果阅读代码中的笔记, 将下面的代码块拷贝到vs code或idea上. 因为在markdown的代码块中宽度有限制, 会影响观看效果.
Given an integer array nums
, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.
Follow up: Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
Example 1:
1 | Input: nums = [1,2,1,3,2,5] |
Example 2:
1 | Input: nums = [-1,0] |
Example 3:
1 | Input: nums = [0,1] |
Constraints:
1 <= nums.length <= 30000
nums
will appear twice, only two integers will appear once.今天刷leetcode 349题的时候, 发现了一个有趣的事情.
原题是求两个数组的交集, public int[] intersection(int[] nums1, int[] nums2)
. 我觉得你们应该也不会觉得这个题难. 转化为两个集合之后很简单就做出来了. 但是, 题目要求返回的是int[]
.
一开始我也没当回事, 以为调用一个toArray()
方法就可以的. 但是这种方法根本不行, 只能得到Integer[]
而不是int[]
. 并且Integer[]
没法强制转换成为int[]
.
事实上, 如果我们想将一个Set<Integer>
转化成int[]
, 还是需要一番操作的.
首先最笨的方法就是new一个int[]
然后逐个元素添加. 但是这种方法显得太古老了一些.
在网上查了一番资料之后, 找到了解决这个问题的办法, 可以实现Integer[]
和int[]
互转. 那就是用Java 8中新引入的特性, Stream.
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Example:
Consider the following matrix:
1 | [ |
Given target = 5
, return true
.
Given target = 20
, return false
.
Given a string s and a string t, check if s is subsequence of t.
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace"
is a subsequence of "abcde"
while "aec"
is not).
Follow up:
If there are lots of incoming S, say S1, S2, … , Sk where k >= 1B, and you want to check one by one to see if T has its subsequence. In this scenario, how would you change your code?
Credits:
Special thanks to @pbrother for adding this problem and creating all test cases.
Example 1:
1 | Input: s = "abc", t = "ahbgdc" |
Example 2:
1 | Input: s = "axc", t = "ahbgdc" |
Constraints:
0 <= s.length <= 100
0 <= t.length <= 10^4
Given an integer array nums
, find the sum of the elements between indices i
and j
(i ≤ j)
, inclusive.
Implement the NumArray
class:
NumArray(int[] nums)
Initializes the object with the integer array nums
.int sumRange(int i, int j)
Return the sum of the elements of the nums
array in the range [i, j]
inclusive (i.e., sum(nums[i], nums[i + 1], ... , nums[j])
)Example 1:
1 | Input |
Constraints:
0 <= nums.length <= 104
-105 <= nums[i] <= 105
0 <= i <= j < nums.length
104
calls will be made to sumRange
.Given a non-empty array of integers, return the k\ most frequent elements.
Example 1:
1 | Input: nums = [1,1,1,2,2,3], k = 2 |
Example 2:
1 | Input: nums = [1], k = 1 |
Note: