03 2017 档案
摘要:索引,MySQL中也叫“键”,是存储引擎中用于快速找到记录的一种数据结构,具体的工作方式就像书本中的索引一样,但是具体的实现方式会有差别。 一.索引分类 B-Tree索引: 优点: MyISAM中,索引根据数据的物理位置引用被索引的行,InnoDB中根据主键引用被索引的行。 B-Tree索引能够加快
阅读全文
摘要:由于Python中,变量作用域为LEGB,所以在函数内部可以读取外部变量,但是在函数外不能读取函数内的变量。但是出于种种原因,我们需要读取函数内的变量时候怎么办?那就是在函数内在加一个函数。 这样,我们就可以看到函数内部的变量了。 上面的inner就是闭包,闭包就是能够读取其他函数内部变量的函数,也
阅读全文
摘要:服务器端: 1.创建一个面向网络的TCP套接字对象socket, 2.绑定地址和端口 3.监听 4.当有客户端连接时候,接受连接并给此连接分配一个新的套接字 5.当客户端发送空信息时候,关闭新分配的套接字 客户端: 1.创建新的套接字 2.连接指定的地址和端口号
阅读全文
摘要:先说下结果吧,结果就是我的IP被豆瓣封了。。。
阅读全文
摘要:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums
阅读全文
摘要:求一个数组中任意四个数的和为target的所有组合 思路:求n个数的和为target,转变为求n-1个书的和为target-num
阅读全文
摘要:计算最少用多少不把word1变为word2, 思路:建立一个dp表,行为word1的长度,宽为word2的长度 1.边界条件,dp[i][0] = i,dp[0][j]=j 2.最优子问题,考虑已经知道word1[0:i-1]转变为word2[0:j-1]的次数,只需要考虑word1[i]和word
阅读全文
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the fo
阅读全文
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, determine t
阅读全文
摘要:一共有n个台阶,每次跳一个或者两个,有多少种走法,典型的Fibonacii问题 还有一种,每次可以跳任意阶,有2^(n-1)种跳法
阅读全文
摘要:一个m*n的表格,每个格子有一个非负数,求从左上到右下最短的路径值 和62,63两个值是同一个思路,建立dp表,记录每个位置到右下角的最短路径的值 占用线性空间的解法:
阅读全文
摘要:用一个数组state记录已经选择的每一行皇后所在的位置,DFS 在整数shu,pie,na中用每个bit位记录已经被占用的 竖,撇,捺
阅读全文
摘要:Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space
阅读全文
摘要:判断一个物体从左上角到右下角有多少种走法
阅读全文
摘要: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,
阅读全文
摘要:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it cost
阅读全文
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文
摘要:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For
阅读全文
摘要:求树的最大深度 1 line python
阅读全文
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and
阅读全文
摘要:Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed n
阅读全文
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet
阅读全文
摘要:判断输入的两棵树是不是相同 判断当前root值,左子树和右子树是否相同 ####注意最后用的是 is 而不是 ==,因为最后判断p和q是不是None, 应该判断是不是同一个对象
阅读全文
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文
摘要:Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST'
阅读全文
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should
阅读全文
摘要:Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be constructed from letters of sequentially adja
阅读全文
摘要:Design a data structure that supports the following two operations: search(word) can search a literal word or a regular expression string containing o
阅读全文
摘要:实现一个字典树
阅读全文
摘要:Sort a linked list using insertion sort. 利用插入排序对一个链表进行排序 思路和数组中的插入排序一样,不过每次都要从链表头部找一个合适的位置,而不是像数组一样可以从要插入的位置开始从后往前找合适的位置
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. 以时间复杂度O(n log n)排序一个链表。 归并排序,在链表中不需要多余的主存空间 tricks:用快慢指针找到中间位置,划分链表
阅读全文
摘要:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red,
阅读全文
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia
阅读全文
摘要:Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]. 合并重叠区间
阅读全文
摘要:Given a text file file.txt, transpose its content. You may assume that each row has the same number of columns and each field is separated by the ' '
阅读全文
摘要:统计words.txt中每个单词出现的次数并排序 解法1: 解法2:
阅读全文
摘要:Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = "anagram", t = "nagaram", return true.s = "rat", t =
阅读全文
摘要:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the
阅读全文
摘要:确定一个数组中有没有重复的值,有的话返回真 解法1: 用python做这样的题感觉。。好简单啊 解法2: 排序,然后遍历 O(Nlog N)
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:统计小于n的素数的个数 如果判断每一个数是不是素数的话,时间会超时,如下 题意要统计素数的个数,那么可以换一种思路,每发现一个素数i,那么i^2,i^2+i...都肯定不是素数
阅读全文
摘要:转载自leetcode评论区:https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-problems I will first give the soluti
阅读全文
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECOD
阅读全文
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating
阅读全文
摘要:Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文
摘要:Given an array of integers, every element appears twice except for one. Find that single one. 找出一个数组中唯一一个只出现了一次的数,其余的都出现了两次
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree [1,null,2,3], return [1,3,2]. 题意:中序遍历树 先写一种比较蠢的方
阅读全文
摘要:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. For example, ret
阅读全文
摘要:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. For example, aft
阅读全文
摘要:The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. The Department table holds all dep
阅读全文
摘要:The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. The Department table hol
阅读全文
摘要:Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: 解法1: 把含有相同字母的字符串分之同一组,对每组的
阅读全文
摘要:Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything
阅读全文
摘要:Write a SQL query to find all duplicate emails in a table named Person.
阅读全文
摘要:The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. Given the Em
阅读全文
摘要:Write a SQL query to find all numbers that appear at least three times consecutively. For example, given the above Logs table, 1 is the only number th
阅读全文
摘要:Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking num
阅读全文
摘要:Write a SQL query to get the nth highest salary from the Employee table. For example, given the above Employee table, the nth highest salary where n =
阅读全文
摘要:Write a SQL query to get the second highest salary from the Employee table. For example, given the above Employee table, the second highest salary is
阅读全文
摘要:Table: Person Table: Address Write a SQL query for a report that provides the following information for each person in the Person table, regardless if
阅读全文

浙公网安备 33010602011771号