
Medium
文章平均质量分 76
iyangdi
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode:M-647. Palindromic Substrings
LeetCode链接 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 subst原创 2017-09-11 11:50:49 · 430 阅读 · 0 评论 -
LeetCode:M-139. Word Break
LeetCode链接 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictiona原创 2017-09-25 13:40:02 · 435 阅读 · 0 评论 -
LintCode:M-接雨水
LintCode链接 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. 您在真实的面试中是否遇到过这个题?原创 2017-08-31 10:27:04 · 614 阅读 · 0 评论 -
LintCode:M-装最多水的容器
LintCode链接 给定 n 个非负整数 a1, a2, ..., an, 每个数代表了坐标中的一个点 (i, ai)。画 n 条垂直线,使得 i 垂直线的两个端点分别为(i, ai)和(i, 0)。找到两条线,使得其与 x 轴共同构成一个容器,以容纳最多水。 注意事项 容器不可倾斜。 您在真实的面试中是否遇到过这个题?原创 2017-08-31 09:42:21 · 293 阅读 · 0 评论 -
LintCode:M-带环链表
LintCode链表 给定一个链表,判断它是否有环。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 -21->10->4->5, tail connects to node index 1,返回 true /** * Definition for ListNode. * public class L原创 2017-08-31 09:37:05 · 244 阅读 · 0 评论 -
LintCode:M-两个链表的交叉
LintCode链接 请写一个程序,找到两个单链表最开始的交叉节点。 注意事项 如果两个链表没有交叉,返回null。在返回结果后,两个链表仍须保持原有的结构。可假定整个链表结构中没有循环。 您在真实的面试中是否遇到过这个题? Yes 样例 下列两个链表: A: a1 → a2原创 2017-08-31 09:36:54 · 291 阅读 · 0 评论 -
LintCode:M-单词切分
LintCode链接 给出一个字符串s和一个词典,判断字符串s是否可以被空格切分成一个或多个出现在字典中的单词。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 s = "lintcode" dict = ["lint","code"] 返回 true 因为"lintcode"可以被空格切分成"lint code"原创 2017-08-31 09:36:42 · 258 阅读 · 0 评论 -
LintCode:M-最长无重复字符的子串
LintCode链接 给定一个字符串,请找出其中无重复字符的最长子字符串。 您在真实的面试中是否遇到过这个题? Yes 样例 例如,在"abcabcbb"中,其无重复字符的最长子字符串是"abc",其长度为 3。 对于,"bbbbb",其无重复字符的最长子字符串为"b",长度为1。 public class Solutio原创 2017-08-30 19:32:35 · 303 阅读 · 0 评论 -
LintCode:M-房屋染色
LintCode链接 这里有n个房子在一列直线上,现在我们需要给房屋染色,分别有红色蓝色和绿色。每个房屋染不同的颜色费用也不同,你需要设计一种染色方案使得相邻的房屋颜色不同,并且费用最小。 费用通过一个nx3 的矩阵给出,比如cost[0][0]表示房屋0染红色的费用,cost[1][2]表示房屋1染绿色的费用。 注意事项 所有费用都是正整数 您原创 2017-08-30 18:38:57 · 483 阅读 · 0 评论 -
LintCode:M-大数相乘
LintCode链接 Given two non-negative integers num1 and num2represented as strings, return the product of num1 and num2 您在真实的面试中是否遇到过这个题? Yes 样例 The length of both num1 and原创 2017-08-30 17:04:33 · 249 阅读 · 0 评论 -
LintCode:M-Expression Expand
LintCode链接 Given an expression s includes numbers, letters and brackets. Number represents the number of repetitions inside the brackets(can be a string or another expression).Please expand exp原创 2017-08-30 15:21:02 · 309 阅读 · 0 评论 -
LintCode:M-K个最近的点
LintCode链接 给定一些 points 和一个 origin,从 points 中找到 k 个离 origin 最近的点。按照距离由小到大返回。如果两个点有相同距离,则按照x值来排序;若x值也相同,就再按照y值排序。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 points = [[4,6],[4,7],[4,4],[2原创 2017-08-30 14:01:50 · 1049 阅读 · 0 评论 -
LintCode:M-抢劫房屋|||
LintCode链接 在上次打劫完一条街道之后和一圈房屋之后,窃贼又发现了一个新的可以打劫的地方,但这次所有的房子组成的区域比较奇怪,聪明的窃贼考察地形之后,发现这次的地形是一颗二叉树。与前两次偷窃相似的是每个房子都存放着特定金额的钱。你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且当相邻的两个房子同一天被打劫时,该系统会自动报警。 算一算,如果今晚去打劫,你最多可以得到多原创 2017-08-30 13:06:15 · 408 阅读 · 0 评论 -
LintCode:M-二叉树的锯齿形遍历
LintCode链接 给出一棵二叉树,返回其节点值的锯齿形层次遍历(先从左往右,下一层再从右往左,层与层之间交替进行) 您在真实的面试中是否遇到过这个题? Yes 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回其锯齿形的层次遍历为:原创 2017-08-30 11:37:18 · 271 阅读 · 0 评论 -
LintCode:M-和大于S的最小子数组
LintCode链接 给定一个由 n 个整数组成的数组和一个正整数 s ,请找出该数组中满足其和 ≥ s 的最小长度子数组。如果无解,则返回 -1。 您在真实的面试中是否遇到过这个题? Yes 样例 给定数组 [2,3,1,2,4,3] 和 s = 7, 子数组 [4,3] 是该条件下的最小长度子数组。原创 2017-08-30 09:15:49 · 517 阅读 · 0 评论 -
LeetCode:M-279. Perfect Squares
LeetCode链接 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. For example, given n = 12, return 3 because 12 =原创 2017-09-25 14:57:13 · 343 阅读 · 0 评论 -
LeetCode:M-105. Construct Binary Tree from Preorder and Inorder Traversal
LeetCode链接 Given preorder and inorder traversal of a tree, construct the binary tree. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left;原创 2017-09-25 22:44:30 · 416 阅读 · 0 评论 -
LeetCode:M-236. Lowest Common Ancestor of a Binary Tree
LeetCode链接 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is define原创 2017-09-11 11:22:00 · 198 阅读 · 0 评论 -
LeetCode:M-3 Sum
LeetCode链接 1、数组排序 2、左边固定一个指针,遍历 3、右边两个移动指针 4、三个指针指向的值求和判断 5、a配对的b/c可能有多个,所以需要将b/c的指针均移动到下一个和b/c不同的值处 TC = O(n^2) class Solution { public List> threeSum(int[] nums) { List> r原创 2017-09-11 10:24:55 · 199 阅读 · 0 评论 -
LeetCode:M-142. Linked List Cycle II
LeetCode链接 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can you solve it without usin原创 2017-09-10 19:26:04 · 257 阅读 · 0 评论 -
LeetCode:M-19. Remove Nth Node From End of List
LeetCode链接 Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second no原创 2017-09-10 21:05:47 · 246 阅读 · 0 评论 -
LeetCode:M-5. Longest Palindromic Substring
LeetCode链接 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also原创 2017-09-10 22:42:05 · 232 阅读 · 0 评论 -
LeetCode:M-2. Add Two Numbers
LeetCode链接 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 tw原创 2017-09-10 20:12:50 · 270 阅读 · 0 评论 -
LeetCode:M-560. Subarray Sum Equals K
LeetCode链接 Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k = 2 Output: 2原创 2017-09-10 10:48:47 · 309 阅读 · 0 评论 -
LintCode:M-丢失的第一个正整数
LintCode链接 给出一个无序的正数数组,找出其中没有出现的最小正整数。 您在真实的面试中是否遇到过这个题? Yes 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许时间复杂度O(n)的算法,并且只能使用常数级别的空间。 pu原创 2017-08-31 17:26:22 · 325 阅读 · 0 评论 -
LintCode:M-不同的二叉查找树个数
LintCode链接 给出 n,问由 1...n 为节点组成的不同的二叉查找树有多少种? 您在真实的面试中是否遇到过这个题? Yes 样例 给出n = 3,有5种不同形态的二叉查找树: 1 3 3 2 1 \ / / / \ \ 3原创 2017-08-31 16:44:17 · 428 阅读 · 0 评论 -
LintCode:M-两个整数相除
LintCode链接 将两个整数相除,要求不使用乘法、除法和 mod 运算符。 如果溢出,返回 2147483647 。 您在真实的面试中是否遇到过这个题? Yes 样例 给定被除数 = 100 ,除数 = 9,返回 11。 标签 二分法 public class Solution { /*原创 2017-08-31 16:25:59 · 348 阅读 · 0 评论 -
LintCode:M-落单的数II
LintCode链接 给出3*n + 1 个的数字,除其中一个数字之外其他每个数字均出现三次,找到这个数字。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 [1,1,2,3,3,3,2,2,4,1] ,返回 4 public class Solution { /** * @param A : An int原创 2017-08-31 15:33:53 · 277 阅读 · 0 评论 -
LintCode:M-最大数
LintCode链接 给出一组非负整数,重新排列他们的顺序把他们组成一个最大的整数。 注意事项 最后的结果可能很大,所以我们返回一个字符串来代替这个整数。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 [1, 20, 23, 4, 8],返回组合最大的整数应为8423201。 publ原创 2017-08-31 15:11:35 · 576 阅读 · 0 评论 -
LeetCode:M-547. Friend Circles
LeetCode链接 There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direc原创 2017-09-25 17:48:57 · 417 阅读 · 0 评论 -
LeetCode:M-287. Find the Duplicate Number
LeetCode链接 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. Assume that there is only one原创 2017-09-25 17:12:56 · 333 阅读 · 0 评论 -
LintCode:M-最大正方形
LintCode链接 在一个二维01矩阵中找到全为1的最大正方形 您在真实的面试中是否遇到过这个题? Yes 样例 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 返回 4 分析 (1)方法一:一般性方法,可以扩展到最大矩形计算 1、以每一行为矩形底,计算每一列的含原创 2017-08-30 11:05:11 · 355 阅读 · 0 评论 -
LintCode:M-带重复元素的排列
LintCode链接 给出一个具有重复数字的列表,找出列表所有不同的排列。 您在真实的面试中是否遇到过这个题? Yes 样例 给出列表 [1,2,2],不同的排列有: [ [1,2,2], [2,1,2], [2,2,1] ] import java.util.*; class Solution {原创 2017-08-30 08:22:59 · 275 阅读 · 0 评论 -
LintCode:M-最近祖先
LinCode链接 给定一棵二叉树,找到两个节点的最近公共父节点(LCA)。 最近公共祖先是两个节点的公共的祖先节点且具有最大深度。 注意事项 假设给出的两个节点都在树中存在 您在真实的面试中是否遇到过这个题? Yes 样例 对于下面这棵二叉树 4 / \ 3 7 / \ 5原创 2017-08-29 09:24:31 · 321 阅读 · 0 评论 -
LintCode:M-Palindrome Partitioning
LintCode:Link Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Have you met this question in a r原创 2017-08-24 23:09:02 · 212 阅读 · 0 评论 -
LintCode:M-Partition Array(快排变种)
LintCode:Link Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that: All elements k are moved to the leftAll elements >= k are moved原创 2017-08-24 22:01:45 · 309 阅读 · 0 评论 -
LintCode:H-Sliding Window Median
LintCode:Link Given an array of n integer, and a moving window(size k), move the window at each iteration from the start of the array, find the median of the element inside the window at ea原创 2017-08-24 19:42:50 · 236 阅读 · 0 评论 -
LintCode:M-二叉查找树中搜索区间
http://www.lintcode.com/zh-cn/problem/search-range-in-binary-search-tree/ 给定两个值 k1 和 k2(k1 您在真实的面试中是否遇到过这个题? Yes 样例 如果有 k1 = 10 和 k2 = 22, 你的程序应该返回 [12, 20, 22].原创 2017-08-21 10:18:27 · 230 阅读 · 0 评论 -
Google算法题:M-Find the Duplicate Number
http://www.lintcode.com/zh-cn/problem/find-the-duplicate-number/ http://www.jiuzhang.com/article/Google%202016%E5%B9%B412%E6%9C%88New%20Grad%20SDE%E7%94%B5%E9%9D%A2%E9%9D%A2%E7%BB%8F/原创 2017-08-20 19:26:15 · 317 阅读 · 0 评论 -
LintCode:M-打劫房屋
http://www.lintcode.com/zh-cn/problem/house-robber/ 假设你是一个专业的窃贼,准备沿着一条街打劫房屋。每个房子都存放着特定金额的钱。你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且 当相邻的两个房子同一天被打劫时,该系统会自动报警。 给定一个非负整数列表,表示每个房子中存放的钱, 算一算,如果今晚去打劫,你最原创 2017-08-20 17:57:38 · 254 阅读 · 0 评论