03 2018 档案

摘要:[抄题]: Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in di 阅读全文
posted @ 2018-03-27 14:55 苗妙苗 阅读(140) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as "word" cont 阅读全文
posted @ 2018-03-26 15:29 苗妙苗 阅读(285) 评论(0) 推荐(0)
摘要:[抄题]: You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend t 阅读全文
posted @ 2018-03-26 11:27 苗妙苗 阅读(166) 评论(0) 推荐(0)
摘要:[抄题]: You are given a string representing an attendance record for a student. The record only contains the following three characters: A student could 阅读全文
posted @ 2018-03-26 10:35 苗妙苗 阅读(126) 评论(0) 推荐(0)
摘要:[抄题]: X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be 阅读全文
posted @ 2018-03-26 09:57 苗妙苗 阅读(181) 评论(0) 推荐(0)
摘要:[抄题]: Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the s 阅读全文
posted @ 2018-03-26 09:20 苗妙苗 阅读(109) 评论(0) 推荐(0)
摘要:[抄题]: Given an array of characters, compress it in-place. The length after compression must always be smaller than or equal to the original array. Eve 阅读全文
posted @ 2018-03-25 10:04 苗妙苗 阅读(126) 评论(0) 推荐(0)
摘要:[抄题]: Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when 阅读全文
posted @ 2018-03-24 22:30 苗妙苗 阅读(120) 评论(0) 推荐(0)
摘要:[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁长 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): 阅读全文
posted @ 2018-03-24 22:07 苗妙苗 阅读(100) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You 阅读全文
posted @ 2018-03-24 21:07 苗妙苗 阅读(146) 评论(0) 推荐(0)
摘要:[抄题]: Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return - 阅读全文
posted @ 2018-03-24 16:43 苗妙苗 阅读(132) 评论(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 阅读全文
posted @ 2018-03-24 15:47 苗妙苗 阅读(154) 评论(0) 推荐(0)
摘要:[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: 最后一位是空格,可能误判lastindexof()。所以必须用.trim() [思维问题]: [一句话思路]: 用函数 再次强调是最后一位的索引是lengt 阅读全文
posted @ 2018-03-20 23:05 苗妙苗 阅读(149) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Example 2: [暴力解法]: 时间分析 阅读全文
posted @ 2018-03-20 21:10 苗妙苗 阅读(206) 评论(0) 推荐(0)
摘要:[抄题]: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a cana 阅读全文
posted @ 2018-03-19 22:19 苗妙苗 阅读(266) 评论(0) 推荐(0)
摘要:[抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Given s = "hello", return "holle". Example 2:Gi 阅读全文
posted @ 2018-03-19 20:15 苗妙苗 阅读(175) 评论(0) 推荐(0)
摘要:[抄题]: Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if th 阅读全文
posted @ 2018-03-19 11:49 苗妙苗 阅读(159) 评论(0) 推荐(0)
摘要:[抄题]: Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word or 阅读全文
posted @ 2018-03-19 09:16 苗妙苗 阅读(147) 评论(0) 推荐(0)
摘要:[抄题]: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to  阅读全文
posted @ 2018-03-19 08:38 苗妙苗 阅读(132) 评论(0) 推荐(0)
摘要:[抄题]: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close i 阅读全文
posted @ 2018-03-18 21:51 苗妙苗 阅读(204) 评论(0) 推荐(0)
摘要:[抄题]: Write a function to find the longest common prefix string amongst an array of strings. 在 "ABCD" "ABEF" 和 "ACEF" 中, LCP 为 "A" 在 "ABCDEFG", "ABCEF 阅读全文
posted @ 2018-03-18 19:55 苗妙苗 阅读(159) 评论(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 th 阅读全文
posted @ 2018-03-18 10:43 苗妙苗 阅读(241) 评论(0) 推荐(0)
摘要:[抄题]: [暴力解法]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: 还停留在 i < len / 2的阶段,不行,应该是指针对撞问题了 [一句话思路]: 先要把字符串转成数组,再转回来,数据结构白学了? [输入量]:空: 正常情况:特大:特小:程 阅读全文
posted @ 2018-03-18 10:01 苗妙苗 阅读(142) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly twoor zero sub-n 阅读全文
posted @ 2018-03-18 08:39 苗妙苗 阅读(191) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Given a non-empty binary searc 阅读全文
posted @ 2018-03-17 22:45 苗妙苗 阅读(495) 评论(0) 推荐(0)
摘要:[抄题]: Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all lef 阅读全文
posted @ 2018-03-17 21:49 苗妙苗 阅读(162) 评论(0) 推荐(0)
摘要:[抄题]: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of  阅读全文
posted @ 2018-03-17 19:45 苗妙苗 阅读(373) 评论(1) 推荐(0)
摘要:[抄题]: Find the sum of all left leaves in a given binary tree. Example: [暴力解法]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: root.left root.right只是递归 阅读全文
posted @ 2018-03-17 15:11 苗妙苗 阅读(121) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: [暴力解法]: 时间分析: 空间分析: [奇葩输出 阅读全文
posted @ 2018-03-17 10:03 苗妙苗 阅读(231) 评论(0) 推荐(0)
摘要:[抄题]: You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to 阅读全文
posted @ 2018-03-16 22:33 苗妙苗 阅读(141) 评论(0) 推荐(0)
摘要:[抄题]: 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 t 阅读全文
posted @ 2018-03-16 18:30 苗妙苗 阅读(189) 评论(0) 推荐(0)
摘要:[抄题]: Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given tar 阅读全文
posted @ 2018-03-16 15:03 苗妙苗 阅读(174) 评论(0) 推荐(0)
摘要:[抄题]: You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not 阅读全文
posted @ 2018-03-15 15:35 苗妙苗 阅读(122) 评论(0) 推荐(0)
摘要:[抄题]: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume th 阅读全文
posted @ 2018-03-14 22:46 苗妙苗 阅读(163) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any 阅读全文
posted @ 2018-03-14 21:58 苗妙苗 阅读(157) 评论(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 longest path 阅读全文
posted @ 2018-03-14 20:43 苗妙苗 阅读(181) 评论(0) 推荐(0)
摘要:[抄题]: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You 阅读全文
posted @ 2018-03-14 18:28 苗妙苗 阅读(285) 评论(0) 推荐(0)
摘要:[抄题]: 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 阅读全文
posted @ 2018-03-14 12:03 苗妙苗 阅读(236) 评论(0) 推荐(0)
摘要:[抄题]: Invert a binary tree. to [暴力解法]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: 以为要分为r.r = l.l, r.l = l.r来讨论,但是其实这样只能最后判断相等。翻转是每一步都要进行的动作,应该尽早开始 阅读全文
posted @ 2018-03-14 11:29 苗妙苗 阅读(131) 评论(0) 推荐(0)
摘要:[抄题]: Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. Example: [暴力解法]: 时间分析 阅读全文
posted @ 2018-03-14 10:06 苗妙苗 阅读(191) 评论(0) 推荐(0)
摘要:[抄题]: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 3 阅读全文
posted @ 2018-03-13 22:16 苗妙苗 阅读(127) 评论(0) 推荐(0)
摘要:[抄题]: The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, 阅读全文
posted @ 2018-03-13 21:48 苗妙苗 阅读(243) 评论(0) 推荐(0)
摘要:[抄题]: Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime c 阅读全文
posted @ 2018-03-13 21:38 苗妙苗 阅读(138) 评论(0) 推荐(0)
摘要:[抄题]: There is a fence with n posts, each post can be painted with one of the k colors. You have to paint all the posts such that no more than two adj 阅读全文
posted @ 2018-03-13 20:36 苗妙苗 阅读(273) 评论(0) 推荐(0)
摘要:[抄题]: There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a 阅读全文
posted @ 2018-03-13 15:41 苗妙苗 阅读(250) 评论(0) 推荐(0)
摘要:[抄题]: On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay the cost, you can either climb one or two st 阅读全文
posted @ 2018-03-13 11:52 苗妙苗 阅读(141) 评论(0) 推荐(0)
摘要:Immutable [抄题]: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: [暴力解法]: 时间分析:n 空间分析:n [ 阅读全文
posted @ 2018-03-13 10:09 苗妙苗 阅读(254) 评论(0) 推荐(0)
摘要:[抄题]: Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is not printe 阅读全文
posted @ 2018-03-12 21:48 苗妙苗 阅读(310) 评论(0) 推荐(0)
摘要:[抄题]: Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, [暴力解法]: 时间分析: 空间分 阅读全文
posted @ 2018-03-12 20:31 苗妙苗 阅读(178) 评论(0) 推荐(0)
摘要:[抄题]: Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a lis 阅读全文
posted @ 2018-03-12 10:58 苗妙苗 阅读(422) 评论(0) 推荐(0)
摘要:[抄题]: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tre 阅读全文
posted @ 2018-03-12 09:21 苗妙苗 阅读(179) 评论(0) 推荐(0)
摘要:[抄题]: 求最多的联通的1的数量 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 (horizonta 阅读全文
posted @ 2018-03-11 21:25 苗妙苗 阅读(176) 评论(0) 推荐(0)
摘要:[抄题]: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are: [暴力解法]: 时间分析: 空间分析 阅读全文
posted @ 2018-03-11 11:20 苗妙苗 阅读(176) 评论(0) 推荐(0)
摘要:[抄题]: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given 阅读全文
posted @ 2018-03-11 10:52 苗妙苗 阅读(147) 评论(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 阅读全文
posted @ 2018-03-11 09:39 苗妙苗 阅读(244) 评论(0) 推荐(0)
摘要:[抄题]: Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally 阅读全文
posted @ 2018-03-11 09:00 苗妙苗 阅读(141) 评论(0) 推荐(0)
摘要:[抄题]: 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回 -1。 如果 source = "source" 和 target = "target",返回 -1。 如果 so 阅读全文
posted @ 2018-03-10 21:55 苗妙苗 阅读(161) 评论(0) 推荐(0)
摘要:[抄题]: 设计一种方式检查一个链表是否为回文链表。1->2->1 就是一个回文链表。 [暴力解法]: 时间分析: 空间分析: [思维问题]: 以为要从从后往前扫描,不知道调用reverse函数。其实找中点、翻转都是链表中直接能用的API [一句话思路]: 后半截儿反过来以后,相同就同时走。走到头说 阅读全文
posted @ 2018-03-10 19:40 苗妙苗 阅读(170) 评论(0) 推荐(0)
摘要:[抄题]: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 -- 阅读全文
posted @ 2018-03-10 09:21 苗妙苗 阅读(296) 评论(0) 推荐(0)
摘要:[抄题]: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin 阅读全文
posted @ 2018-03-09 21:56 苗妙苗 阅读(234) 评论(0) 推荐(0)
摘要:[抄题]: Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possibl 阅读全文
posted @ 2018-03-09 20:03 苗妙苗 阅读(810) 评论(0) 推荐(0)
摘要:[抄题]: A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED repre 阅读全文
posted @ 2018-03-09 10:03 苗妙苗 阅读(211) 评论(0) 推荐(0)
摘要:[抄题]: 在一个二维01矩阵中找到全为1的最大正方形 返回 4 [暴力解法]: 时间分析: 空间分析:i j 中保留一排,用指针数组来优化空间存储 [思维问题]: [一句话思路]: 棋盘类dp也是用扩展,不过是从右下角开始扩展 最大扩展中的最小值,没见过 [输入量]:空: 正常情况:特大:特小:程 阅读全文
posted @ 2018-03-06 15:40 苗妙苗 阅读(212) 评论(0) 推荐(0)
摘要:[抄题]: 假设你是一个专业的窃贼,准备沿着一条街打劫房屋。每个房子都存放着特定金额的钱。你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且 当相邻的两个房子同一天被打劫时,该系统会自动报警。 给定一个非负整数列表,表示每个房子中存放的钱, 算一算,如果今晚去打劫,你最多可以得到多少钱 在 阅读全文
posted @ 2018-03-06 09:13 苗妙苗 阅读(250) 评论(0) 推荐(0)
摘要:TRAVERSE 是一个小人, 拿着一个记事本, 顺着二叉树走, 走过一个, 在本子上面记下来 DIVIDE & CONQUER 是女王接到这个任务, 找两个小弟A和B, 让A和B先去收集, A收集了[2, 4, 5], B收集了[3], 最后女王把A, B的结果汇总加上自己是1,得到答案[1, 2 阅读全文
posted @ 2018-03-06 00:05 苗妙苗 阅读(350) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个字符串,找到最多有k个不同字符的最长子字符串。eg:eceba, k = 3, return eceb [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画 阅读全文
posted @ 2018-03-05 09:23 苗妙苗 阅读(481) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个字符串source和一个目标字符串target,在字符串source中找到包括所有目标字符串字母的子串。 在答案的子串中的字母在目标字符串中是否需要具有相同的顺序? ——不需要。 给出source = "ADOBECODEBANC",target = "ABC" 满足要求的解 " 阅读全文
posted @ 2018-03-04 19:57 苗妙苗 阅读(347) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个字符串,请找出其中无重复字符的最长子字符串。 例如,在"abcabcbb"中,其无重复字符的最长子字符串是"abc",其长度为 3。 对于,"bbbbb",其无重复字符的最长子字符串为"b",长度为1。 [暴力解法]: 时间分析: 空间分析: [思维问题]: hashset, h 阅读全文
posted @ 2018-03-04 15:26 苗妙苗 阅读(204) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个由 n 个正整数组成的数组和一个正整数 s ,请找出该数组中满足其和 ≥ s 的最小长度子数组。如果无解,则返回 -1。 给定数组 [2,3,1,2,4,3] 和 s = 7, 子数组 [4,3] 是该条件下的最小长度子数组。 [暴力解法]: 时间分析: 空间分析: [思维问题] 阅读全文
posted @ 2018-03-04 09:24 苗妙苗 阅读(353) 评论(0) 推荐(0)
摘要:[抄题]: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two 阅读全文
posted @ 2018-03-03 20:19 苗妙苗 阅读(139) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个整数数组,在该数组中,寻找三个数,分别代表三角形三条边的长度,问,可以寻找到多少组这样的三个数来组成三角形? [暴力解法]: 全部都用for循环 时间分析: 空间分析: [思维问题]: 可以用两层循环:for循环中嵌套while,用过但是没意识 [一句话思路]: [输入量]:空: 阅读全文
posted @ 2018-03-03 15:44 苗妙苗 阅读(232) 评论(0) 推荐(0)
摘要:[抄题]: Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the 阅读全文
posted @ 2018-03-03 10:04 苗妙苗 阅读(300) 评论(0) 推荐(0)
摘要:[抄题]: 给定一个包含 n 个整数的数组,和一个大小为 k 的滑动窗口,从左到右在数组中滑动这个窗口,找到数组中每个窗口内的中位数。(如果数组个数是偶数,则在该窗口排序数字后,返回第 N/2 个数字。) 对于数组 [1,2,7,8,5], 滑动大小 k = 3 的窗口时,返回 [2,7,7] 最初 阅读全文
posted @ 2018-03-02 11:18 苗妙苗 阅读(448) 评论(0) 推荐(0)