自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 ConcurrentHashMap 源码解析

JDK 1.8 中的 ConcurrentHashMap 源码解析

2022-08-27 18:39:21 1803 5

原创 InnoDB的B+索引

本文主要讲述 B+ 树在 InnoDB 索引下的实现和产生的背景,不涉及 B+ 树节点的更新算法。

2022-07-21 23:24:53 241

原创 MySQL的数据页结构和记录的管理

MySQL 的页有多种类型,本文主要讲述数据页的结构和记录管理,数据页也就是表中一行一行的数据组成的页。

2022-07-17 15:27:43 436

原创 一条SQL语句的执行过程

本文站在后端开发的角度,讲述一条SQL从客户端发送到MySQL服务器进行处理,并将结果返回给客户端的过程。这个过程中涉及的操作会在后面的文章中做详细的分析。

2022-07-14 16:03:49 428 1

原创 Stream将List转成Map的坑

1. 背景常规 list 转 map 的方法:Map<String, String> map = new HashMap<>();for (User user : list) { map.put(user.getName(), user.getAddress());}这种方式没什么问题,就是代码不够简洁美观,而且逼格不够高。可以通过 Java8 中的 Stream 流来轻松实现这个功能。Map<String, String> map = list.s

2020-08-02 16:27:06 2320

原创 Java 注解概论

Java 注解概论注解可以简化主流程代码,具体分为以下3个方面:1.生成文档,在注释中随处可见,例如 @param,@return 等;2.代替配置文件,Spring 框架经常使用注解来代替XML配置文件,精简代码结构;3.编译时进行格式检查,例如 @Override;1. 定义注解所有注解都继承了 Annotation 接口,但不是采用 implement 关键字实现,而是用 @interface 声明接口来实现继承的逻辑,表示这是一个注解。例如,常见的 @Override 注解。@Targ

2020-07-05 17:34:37 151

原创 Java 函数式编程概论

1. 函数的基本概念函数就是将输入转换一种形式进行输出。以数学中的函数为例,假设有一个函数 f(x)=3x+1f(x) = 3x + 1f(x)=3x+1,当输入 x=1x = 1x=1 时,输出 f(x)=4f(x) = 4f(x)=4。Java 中函数的概念类似,以 Comparator 类为例,下面代码是一个函数式接口。其中方法 applyAsInt 表示一种转换关系,相当于数学函数中的 ...

2020-04-17 23:38:28 300

原创 基于Anaconda的graphviz使用问题

想要用graphviz可视化sklearn生成的决策树,运行网上的例子提示无法找到graphviz.exe文件。在sklearn的官网中找到了解决办法。 在cmd界面输入conda install python-graphviz来安装graphviz。 举一个例子:from sklearn.datasets import load_irisfrom sklearn import tr

2018-01-23 12:28:41 4615

原创 226. Invert Binary Tree Difficult: Easy

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1算法分析:可以用层序遍历的方法交换左右子树,也可以直接递归。C语言版struct TreeNode* invertTree(struct TreeNode* roo

2017-11-03 22:48:09 232

原创 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.算法解析:既可以用深度优先搜索,也可以用广度优先搜索,前者可以节省代码,后者可以提高速

2017-10-28 22:10:01 292

原创 695. Max Area of Island Difficulty: Easy

Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surroun

2017-10-28 21:28:22 258

原创 526. Beautiful Arrangement Difficulty: Medium

Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <= i <

2017-10-28 21:13:22 231

原创 136. Single Number Difficulty: Medium

Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me

2017-10-14 09:49:01 206

原创 515. Find Largest Value in Each Tree Row Difficulty: Medium

You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]算法分析:考查BFS,或者说是树的层序遍历,但要注意区分每一层。我

2017-10-13 15:42:28 227

原创 647. Palindromic Substrings Difficulty: Medium

Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of

2017-10-12 14:04:10 219

原创 540. Single Element in a Sorted Array Difficulty:Medium

Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once.Example 1:Input: [1,1,2,3,3

2017-10-11 20:33:46 309

原创 406. Queue Reconstruction by Height Difficulty : Medium

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this p

2017-10-10 21:18:14 188

原创 442. Find All Duplicates in an Array Difficulty : Medium

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra space

2017-10-10 19:17:07 261

原创 513. Find Bottom Left Tree Value Difficulty : mediate

Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3 / / \ 4 5 6

2017-10-04 23:06:39 223

原创 463. Island Perimeter Difficulty : Easy

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s

2017-10-03 11:46:40 216

原创 669. Trim a Binary Search Tree Difficulty : Easy

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 result

2017-10-03 10:57:08 204

原创 566. Reshape the Matrix Difficult : Easy

In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensio

2017-10-03 10:09:41 253

原创 557. Reverse Words in a String III 难度:简单

Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"Output

2017-09-28 16:04:04 352

原创 500. Keyboard Row 难度:简单

Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Dad", "Peace"]Outp

2017-09-27 16:39:33 244

原创 在for循环遍历列表的过程中不能删除列表中的元素

在刷题的时候碰到一件很有意思的事,就是在Python中用循环遍历列表中元素的时候,感觉还是按照下标进行访问的,这时如果删除掉了已经遍历到的元素的时候,那么删除元素之后的列表的下标会重新排序,但是循环还是按照循环开始的时候列表的下标进行访问的,这时会导致有些元素访问不到的情况。具体见代码。words = ["a", "b", "c", "d"]flag = 1for word in words:

2017-09-27 14:05:38 1972

原创 476. Number Complement 难度:简单

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: 1. The given integer is guaranteed to fit within the range of a 3

2017-09-24 11:14:44 571

原创 338. Counting Bits 难度:中等

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh

2017-09-23 21:50:33 210

原创 561. Array Partition I; Difficulty : Easy

Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl

2017-09-18 17:19:35 420

原创 617. Merge Two Binary Trees; Difficulty:Easy

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. T

2017-09-18 16:33:52 406

原创 657. Judge Route Circle-Difficulty:Easy

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is represented by a

2017-09-17 19:54:25 254

原创 文章标题

Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum tree constructed from

2017-09-17 17:19:11 194

原创 461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note: 0≤x,y<2310 ≤ x, y <

2017-09-16 17:12:55 216

原创 1043. Is It a Binary Search Tree (25)

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key.The right subtr

2017-09-14 21:57:36 210

原创 1042. Shuffling Machine (20)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers

2017-09-11 21:05:08 196

原创 1041. Be Unique (20)

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a

2017-09-07 16:54:28 215

原创 1040. Longest Symmetric String (25)

Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given “Is PAT&TAP symmetric?”, the longest symmetric sub-string is “s PAT&TAP s”, hence you must

2017-09-07 16:21:52 201

原创 1038. Recover the Smallest Number (30)

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87

2017-08-30 12:14:59 187

原创 1037. Magic Coupon (25)

The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product ba

2017-08-27 16:16:21 224

原创 1036. Boys vs Girls (25)

This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each input file contains one test c

2017-08-21 15:47:49 245

原创 1035. Password (20)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L i

2017-08-20 12:47:12 217

空空如也

空空如也

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

TA关注的人

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