07 2018 档案

摘要:1、二叉树的先序遍历。 节点->左孩子->右孩子 用递归很容易解决,但是会遇到内存溢出情况。用栈可以解决找个问题。 根据前序遍历访问的顺序,优先访问根结点,然后再分别访问左孩子和右孩子。即对于任一结点,其可看做是根结点,因此可以直接访问,访问完之后,若其左孩子不为空,按相同规则访问它的左子树;当访问 阅读全文
posted @ 2018-07-31 23:07 Lin.B 阅读(283) 评论(0) 推荐(0)
摘要:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Exp 阅读全文
posted @ 2018-07-30 22:27 Lin.B 阅读(177) 评论(0) 推荐(0)
摘要:1、字符串的全排列 题目:{a,b,c}要求输出{abc,acb,bac,bca,cab,cba}。 字符串全排列可以把字符串看成两个部分,第一个部分为它的一个字符,第二部分是后面的字符。 分两步完成:首先求所有可能出现在第一个位置的字符,即把第一个字符与后面的所有字符交换。第二步固定第一个字符,求 阅读全文
posted @ 2018-07-29 23:26 Lin.B 阅读(3048) 评论(0) 推荐(0)
摘要:问题:输入一个整形数组,里面又正数也有负数。数组中一个或连续多个整数组成一个子数组,求所有子数组和的最大值。 典型的动态规划思想,因为每个状态都和前一个状态紧密相关。 因为这是一个一维数组,所以我们优先考虑用一维数组dp来做。 1、维护一个dp数组,dp[i]表示以第i个位置结尾的子数组的和的最大值 阅读全文
posted @ 2018-07-29 21:51 Lin.B 阅读(907) 评论(0) 推荐(0)
摘要:Top K问题比较常见啦,这里总结一下方法。 1、用最小堆来做。 思路是先利用数组中前k个数字建一个最小堆,然后将剩余元素与堆顶元素进行比较,如果某个元素比堆顶元素大,就替换掉堆顶元素,并且重新调整成最小堆。 到这里,堆中保存着的其实是前k个最大的数字。堆顶就是第K个最大的数字。这样前k个,第k个都 阅读全文
posted @ 2018-07-28 23:00 Lin.B 阅读(738) 评论(0) 推荐(0)
摘要:1、将一个字符串转乘整数 例如“1234”->1234 现在研究这段代码,有什么问题呢?首先,没有判断正负号,如果输入是“-1234”,就错了;其次,没有考虑int变量的范围,如果超过Integer.maxvalue,程序就会崩溃;最后就是如果输入有特殊字符,比如输入“123#¥%34”,这个时候应 阅读全文
posted @ 2018-07-27 11:53 Lin.B 阅读(250) 评论(0) 推荐(0)
摘要:字符串编辑距离 字符串的编辑距离,又称为Levenshtein距离,由俄罗斯的数学家Vladimir Levenshtein在1965年提出。是指利用字符操作,把字符串A转换成字符串B所需要的最少操作数。其中,字符操作包括: 删除一个字符 插入一个字符 修改一个字符 例如对于字符串"if"和"iff 阅读全文
posted @ 2018-07-26 23:15 Lin.B 阅读(4832) 评论(0) 推荐(1)
摘要:1、Reverse Linked ListⅠ Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be r 阅读全文
posted @ 2018-07-26 21:43 Lin.B 阅读(203) 评论(0) 推荐(0)
摘要:1、判断一个迷宫是否有出口 这个题目是我自己编的,leetcode上并没有这样的题目。为了锻炼自己的DFS,这个题目应该还是比较简单的,用深搜就可以完成,和之前做的max area of island有异曲同工之妙。 poll出迷宫问题: 、 如图所示的迷宫,0代表可以走,1代表有墙。要求从左上角到 阅读全文
posted @ 2018-07-25 22:12 Lin.B 阅读(1462) 评论(0) 推荐(0)
摘要: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.) Yo 阅读全文
posted @ 2018-07-25 17:56 Lin.B 阅读(151) 评论(0) 推荐(0)
摘要:Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follo 阅读全文
posted @ 2018-07-25 16:58 Lin.B 阅读(152) 评论(0) 推荐(0)
摘要:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the 阅读全文
posted @ 2018-07-24 14:12 Lin.B 阅读(142) 评论(0) 推荐(0)
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: 阅读全文
posted @ 2018-07-23 18:18 Lin.B 阅读(119) 评论(0) 推荐(0)
摘要:今天总结一下用Floyd算法来判断链表中是否有环,如果有环,如何找到环的入口。这一系列问题。 1、Linked List Cycle Ⅰ Given a linked list, determine if it has a cycle in it. Follow up:Can you solve i 阅读全文
posted @ 2018-07-23 17:28 Lin.B 阅读(189) 评论(0) 推荐(0)
摘要:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. 阅读全文
posted @ 2018-07-23 16:23 Lin.B 阅读(148) 评论(0) 推荐(0)
摘要:今天来总结一下Missing Number一系列问题 1、Find All Numbers Disappeared in an Array Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements 阅读全文
posted @ 2018-07-23 15:54 Lin.B 阅读(270) 评论(0) 推荐(0)
摘要:Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we tak 阅读全文
posted @ 2018-07-19 17:56 Lin.B 阅读(169) 评论(0) 推荐(0)
摘要:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This 阅读全文
posted @ 2018-07-18 19:46 Lin.B 阅读(150) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: T 阅读全文
posted @ 2018-07-18 16:42 Lin.B 阅读(191) 评论(0) 推荐(0)
摘要:Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one cha 阅读全文
posted @ 2018-07-17 16:48 Lin.B 阅读(150) 评论(0) 推荐(0)
摘要:Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. Example 1: Input: s1 = "sea", s2 = "eat" Output: 阅读全文
posted @ 2018-07-17 16:39 Lin.B 阅读(124) 评论(0) 推荐(0)
摘要: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 c 阅读全文
posted @ 2018-07-16 22:52 Lin.B 阅读(130) 评论(0) 推荐(0)
摘要:You are given a string representing an attendance record for a student. The record only contains the following three characters: 'A' : Absent. 'L' : L 阅读全文
posted @ 2018-07-16 20:45 Lin.B 阅读(125) 评论(0) 推荐(0)
摘要:Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there ar 阅读全文
posted @ 2018-07-16 11:51 Lin.B 阅读(91) 评论(0) 推荐(0)
摘要:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath betwee 阅读全文
posted @ 2018-07-16 11:06 Lin.B 阅读(144) 评论(0) 推荐(0)
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl 阅读全文
posted @ 2018-07-15 18:03 Lin.B 阅读(121) 评论(0) 推荐(0)
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumR 阅读全文
posted @ 2018-07-15 17:32 Lin.B 阅读(114) 评论(0) 推荐(0)
摘要:House RobberⅠ You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constrai 阅读全文
posted @ 2018-07-15 17:02 Lin.B 阅读(142) 评论(0) 推荐(0)
摘要: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 r 阅读全文
posted @ 2018-07-15 15:19 Lin.B 阅读(111) 评论(0) 推荐(0)
摘要:今天处理一下一系列题目:Next Greater Element系列。 Next Greater Element I You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are su 阅读全文
posted @ 2018-07-13 23:16 Lin.B 阅读(165) 评论(0) 推荐(0)
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia 阅读全文
posted @ 2018-07-13 19:53 Lin.B 阅读(105) 评论(0) 推荐(0)
摘要:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of th 阅读全文
posted @ 2018-07-13 12:07 Lin.B 阅读(121) 评论(0) 推荐(0)
摘要:Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in th 阅读全文
posted @ 2018-07-13 11:44 Lin.B 阅读(130) 评论(0) 推荐(0)
摘要:Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, 阅读全文
posted @ 2018-07-13 10:41 Lin.B 阅读(120) 评论(0) 推荐(0)
摘要:There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. Yo 阅读全文
posted @ 2018-07-12 11:58 Lin.B 阅读(171) 评论(0) 推荐(0)
摘要: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 so 阅读全文
posted @ 2018-07-11 17:50 Lin.B 阅读(94) 评论(0) 推荐(0)
摘要:Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Input: 5 O 阅读全文
posted @ 2018-07-11 17:39 Lin.B 阅读(133) 评论(0) 推荐(0)
摘要:We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1. Return the same tree where every subtree 阅读全文
posted @ 2018-07-11 16:32 Lin.B 阅读(128) 评论(0) 推荐(0)
摘要:Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temp 阅读全文
posted @ 2018-07-11 15:02 Lin.B 阅读(122) 评论(0) 推荐(0)
摘要:Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twi 阅读全文
posted @ 2018-07-10 17:51 Lin.B 阅读(126) 评论(0) 推荐(0)
摘要:A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com 阅读全文
posted @ 2018-07-10 16:48 Lin.B 阅读(196) 评论(0) 推荐(0)
摘要:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals 阅读全文
posted @ 2018-07-10 16:06 Lin.B 阅读(135) 评论(0) 推荐(0)
摘要:Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: 阅读全文
posted @ 2018-07-09 16:57 Lin.B 阅读(301) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the dep 阅读全文
posted @ 2018-07-08 16:51 Lin.B 阅读(138) 评论(0) 推荐(0)
摘要:Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. Example 1: Input: S = 阅读全文
posted @ 2018-07-08 16:05 Lin.B 阅读(129) 评论(0) 推荐(0)
摘要:We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). N 阅读全文
posted @ 2018-07-05 20:42 Lin.B 阅读(109) 评论(0) 推荐(0)
摘要:使用滑动窗口法来解决substring问题的模板如下: 这里是leetcode大神给出的通用模板,针对每个题目的不同会有一些差别。但是整体的思路就是两个指针,一个map,一个counter标记(视题目而定,也可能没有)。具体的思路就是先滑动窗口,找到一个窗口内包含一个结果;然后缩小窗口,判断结果。 阅读全文
posted @ 2018-07-05 17:14 Lin.B 阅读(162) 评论(0) 推荐(0)
摘要:Valid Anagram Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: s = "anagram", t = "nagaram" Output 阅读全文
posted @ 2018-07-04 21:21 Lin.B 阅读(148) 评论(0) 推荐(0)
摘要:In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Th 阅读全文
posted @ 2018-07-04 16:15 Lin.B 阅读(146) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2018-07-03 22:02 Lin.B 阅读(124) 评论(0) 推荐(0)
摘要:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every 阅读全文
posted @ 2018-07-03 17:28 Lin.B 阅读(148) 评论(0) 推荐(0)