N皇后问题

题目 The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively. For example, There exist two distinct solutions to

sqrtx 求整数平方根

题目 Implement int sqrt(int x). Compute and return the square root of x. x is guaranteed to be a non-negative integer. 我的思路 我能想到的只有暴力方法,从一个位置开始,一步一步加一,直到找到平方根。 代码 int mySqrt(int x) { long long times

Brent判圈算法学习

判断一个链接有没有环,很著名的算法是Floyd判圈算法,也叫龟兔算法。但是,原来还有一种算法,可以比Floyd更快一点,这种算法叫做Bren

find-all-duplicates-in-an-array

题目 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 and in O(n) runtime? Example: Input: [4,3,2,7,8,2,3,1] Output: [2,3] 思路 想了好久,终于想出来了。首先,题目

battelships-in-a-board

题目 Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules: You receive a valid board, made of only battleships or empty slots. Battleships can only be placed horizontally or vertically. In other words, they can only be made of the shape 1xN (1 row, N columns) or Nx1 (N

array-partition-i

题目 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 possible. Note: n is a positive integer, which is in the range of [1, 10000]. All the integers in the array will be in the range

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. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will

maxiumn-subarray 和最大的子数组

题目 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] has the largest sum = 6. 思路一 首先,可以直接两重循环,找到所有的子数组,

浅谈后端业务系统设计

这里将说说个人对设计的想法,必然会有争议之处,内容包括系统之间设计,系统内部模块之间设计,细到每个函数的设计。 系统设计 不要为了拆系统而拆系统

记一次redis连接数超限的事故

最近出了一次事故,应用crash,并报错: max number of clients reached. 查了一下reids的连接: netstat -anp |grep 6379 | wc -l 发现,连接数达10000多个,大致扫了一下,发现