文章 217
评论 6
浏览 143930
Array - 36. Valid Sudoku

Array - 36. Valid Sudoku

Determine if a 9x9 Sudoku board is valid.

DFS&BFS - 37. Sudoku Solver

DFS&BFS - 37. Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.

String - 44. Wildcard Matching

String - 44. Wildcard Matching

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

String - 67. Add Binary

String - 67. Add Binary

Given two binary strings, return their sum (also a binary string).

性能测试工具——wrk

性能测试工具——wrk

wrk 是一款简单的 HTTP 压测工具。

String - 71. Simplify Path

String - 71. Simplify Path

Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.

Spring事务的传播行为

Spring事务的传播行为

事务的传播特性就是当一个事务方法被另一个事务方法调用的时候,这个事务方法应该如何执行。

Go modules 简介

Go modules 简介

Golang的版本管理视频推荐:Go with Versions - GopherConSG 2018

String - 8. String to Integer (atoi)

String - 8. String to Integer (atoi)

8.String to Integer (atoi) Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect....

Array - 16. 3Sum Closest

Array - 16. 3Sum Closest

16. 3Sum Closest Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Example: Given array nums = [-1, 2, 1, -4], and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). 思路: 给定一个数组,找出三个数的和最接近target,和15题很像,做法类似,都是对于每一位元素,用双指针找出另外两个数,更新出一个最小的结果就可以。 代码: go: f....

Array - 15. 3Sum

Array - 15. 3Sum

15. 3Sum Given an array nums of n integers, are there elements a, b, c in nums 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 duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] 思路: 找出数组中三数和的所有组合,解决思路是首先做一个排序,然后对于每一位元素,去找出剩下数组中找出两个数和当前元素三个数和为0就可以,主要要留意重复元素就不用了计算....

LinkedList - 2. Add Two Numbers

LinkedList - 2. Add Two Numbers

2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807. 思路: 题目意思是给两个链表,把这两个链表,一个链表代....

Tree - 450. Delete Node in a BST

Tree - 450. Delete Node in a BST

450. Delete Node in a BST Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can be divided into two stages: Search for a node to remove. If the node is found, delete the node. Note: Time complexity should be O(height of tree). Example: root = [5,3,6,2,4,null,7] key = 3 5 / \ 3 6 / \ \ 2 4 7 Given key to delete is 3. So we find the node with value 3 and de....

Tree - 145. Binary Tree Postorder Traversal

Tree - 145. Binary Tree Postorder Traversal

145. Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 2 / 3 Output: [3,2,1] Follow up: Recursive solution is trivial, could you do it iteratively? 思路: 二叉树后序遍历,递归和迭代来做,迭代也是使用list容器来充当栈,后序遍历和前序后序遍历主要特点在于父节点会被访问两次,所以使用一个辅助指针preVisited来记录是否是第二次访问这个节点。 代码: go: /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /* ....

Tree - 94. Binary Tree Inorder Traversal

Tree - 94. Binary Tree Inorder Traversal

94. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 2 / 3 Output: [1,3,2] Follow up: Recursive solution is trivial, could you do it iteratively? 思路: 二叉树的中序遍历,先访问左子树然后中间节点然后右子树。迭代也是使用list容器来充当栈 代码: go : /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // recursive /*func inorderTraversal(root *TreeNode) []int { var res [....

Tree - 144. Binary Tree Preorder Traversal

Tree - 144. Binary Tree Preorder Traversal

144. Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 2 / 3 Output: [1,2,3] Follow up: Recursive solution is trivial, could you do it iteratively? 思路: 二叉树的先序遍历,递归求解和迭代,迭代使用list容器的链表代替栈来做 代码: go: /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // recursive /*func preorderTraversal(root *TreeNode) []int { var ....

Array - 42. Trapping Rain Water Hard

Array - 42. Trapping Rain Water Hard

42. Trapping Rain Water Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image! Example: Input: [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 思路: 题目意思是给定一个数组,数值代表了高度,求解可以装多少水,仔细分析可以发现,对于任意一位能存储多少水是取....

Tree - 687. Longest Univalue Path

Tree - 687. Longest Univalue Path

687. Longest Univalue Path Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of path between two nodes is represented by the number of edges between them.   Example 1: Input: 5 / \ 4 5 / \ \ 1 1 5 Output: 2   Example 2: Input: 1 / \ 4 5 / \ \ 4 4 5 Output: 2   Note: The given binary tree has not more than 10000 nodes. The height of the tree is n....

DFS - 980. Unique Paths III

DFS - 980. Unique Paths III

980. Unique Paths III On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square.  There is exactly one starting square. 2 represents the ending square.  There is exactly one ending square. 0 represents empty squares we can walk over. -1 represents obstacles that we cannot walk over. Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square ....

Dynamic Programming - 375. Guess Number Higher or Lower II

Dynamic Programming - 375. Guess Number Higher or Lower II

375. Guess Number Higher or Lower II We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I’ll tell you whether the number I picked is higher or lower. However, when you guess a particular number x, and you guess wrong, you pay $x. You win the game when you guess the number I picked. Example: n = 10, I pick 8. First round: You guess 5, I tell you that it's higher. You pay ....

Nothing just happens, it's all part of a plan.