02 2017 档案

摘要:Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs are consist of lowercase letters a-z. 解法: Trie(字典树)的 阅读全文
posted @ 2017-02-21 23:34 Strugglion 阅读(497) 评论(0) 推荐(0)
摘要:Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right, up or do 阅读全文
posted @ 2017-02-21 20:36 Strugglion 阅读(359) 评论(0) 推荐(0)
摘要:Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. Follow up: Wh 阅读全文
posted @ 2017-02-21 18:56 Strugglion 阅读(360) 评论(0) 推荐(0)
摘要:Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number m 阅读全文
posted @ 2017-02-21 17:29 Strugglion 阅读(307) 评论(0) 推荐(0)
摘要:水塘抽样是一系列的随机算法,其目的在于从包含n个项目的集合S中选取k个样本,其中n为一很大或未知的数量,尤其适用于不能把所有n个项目都存放到主内存的情况。 在高德纳的计算机程序设计艺术中,有如下问题:可否在一未知大小的集合中,随机取出一元素?。或者是Google面试题: I have a linke 阅读全文
posted @ 2017-02-21 16:49 Strugglion 阅读(9362) 评论(2) 推荐(2)
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib 阅读全文
posted @ 2017-02-21 15:08 Strugglion 阅读(247) 评论(0) 推荐(0)
摘要:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conca 阅读全文
posted @ 2017-02-21 13:22 Strugglion 阅读(313) 评论(0) 推荐(0)
摘要:Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 解法: 这道题让我们求两数相除,而且规定我们不能用乘法,除法和取余操作。 采 阅读全文
posted @ 2017-02-20 22:24 Strugglion 阅读(225) 评论(0) 推荐(0)
摘要:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 解法: 这道题让我们在一个字符串中找另一个字符串 阅读全文
posted @ 2017-02-20 18:01 Strugglion 阅读(530) 评论(0) 推荐(0)
摘要:Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you 阅读全文
posted @ 2017-02-20 17:43 Strugglion 阅读(176) 评论(0) 推荐(0)
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space fo 阅读全文
posted @ 2017-02-20 16:47 Strugglion 阅读(152) 评论(0) 推荐(0)
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to 阅读全文
posted @ 2017-02-20 16:28 Strugglion 阅读(165) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your 阅读全文
posted @ 2017-02-20 14:27 Strugglion 阅读(156) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解法1: 采用递归的方法,不管合并几个,归根到底还是需要两两合并。 首先想到的是前两个先合并,然后再跟 阅读全文
posted @ 2017-02-19 23:59 Strugglion 阅读(206) 评论(0) 推荐(0)
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: 解 阅读全文
posted @ 2017-02-18 23:53 Strugglion 阅读(414) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 解法: 新建一个 阅读全文
posted @ 2017-02-18 21:36 Strugglion 阅读(222) 评论(0) 推荐(0)
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the 阅读全文
posted @ 2017-02-18 17:32 Strugglion 阅读(162) 评论(0) 推荐(0)
摘要:Given a linked list, remove the nth node from the end of list and return its head. For example, Note:Given n will always be valid.Try to do this in on 阅读全文
posted @ 2017-02-18 17:02 Strugglion 阅读(135) 评论(0) 推荐(0)
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic 阅读全文
posted @ 2017-02-18 00:44 Strugglion 阅读(3339) 评论(0) 推荐(0)
摘要:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho 阅读全文
posted @ 2017-02-17 15:50 Strugglion 阅读(208) 评论(0) 推荐(0)
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2017-02-17 00:28 Strugglion 阅读(320) 评论(0) 推荐(0)
摘要:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of 阅读全文
posted @ 2017-02-16 22:29 Strugglion 阅读(2468) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings. 解法: 广度优先搜索:先比较所有字符串的第一个字符,然后比较第二个。。。。如果某一行没有了(说明其为最短的单词)或者遇到不匹配 阅读全文
posted @ 2017-02-16 16:15 Strugglion 阅读(150) 评论(0) 推荐(0)
摘要:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解法: 只要考虑两种情况即可: 第一,如果当前数字是最后一个数字,或者之后的数字比它 阅读全文
posted @ 2017-02-16 00:26 Strugglion 阅读(157) 评论(0) 推荐(0)
摘要:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 解释: 罗马数字采用七个罗马字母作数字、即Ⅰ(1)、X(10)、C(100)、M(1 阅读全文
posted @ 2017-02-15 22:51 Strugglion 阅读(205) 评论(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 endpo 阅读全文
posted @ 2017-02-15 17:09 Strugglion 阅读(164) 评论(0) 推荐(0)
摘要:Implement regular expression matching with support for '.' and '*'. 解法1: 这道题中的*表示*之前的那个字符可以有0个,1个或是多个,就是说,字符串a*b,可以表示b或是aaab,即a的个数任意;字符串.*b,可以表示b或是xyz 阅读全文
posted @ 2017-02-14 22:11 Strugglion 阅读(261) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thi 阅读全文
posted @ 2017-02-13 00:28 Strugglion 阅读(164) 评论(0) 推荐(0)
摘要:Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below 阅读全文
posted @ 2017-02-12 23:57 Strugglion 阅读(194) 评论(0) 推荐(0)
摘要:Reverse digits of an integer. Example1: Example2: Have you thought about this? Here are some good questions to ask before coding. Bonus points for you 阅读全文
posted @ 2017-02-12 17:58 Strugglion 阅读(185) 评论(0) 推荐(0)
摘要:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font 阅读全文
posted @ 2017-02-12 15:56 Strugglion 阅读(187) 评论(0) 推荐(0)
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 求字符串中的最大回文子串(从左往右和从右往左读一样的子串)。 Exa 阅读全文
posted @ 2017-02-12 00:51 Strugglion 阅读(318) 评论(0) 推荐(0)
摘要:关于这三个类在字符串处理中的位置不言而喻,那么他们到底有什么优缺点,到底什么时候该用谁呢?下面我们从以下几点说明一下。 1.三者在执行速度方面的比较:StringBuilder > StringBuffer > String 2.String <(StringBuffer,StringBuilder 阅读全文
posted @ 2017-02-11 15:32 Strugglion 阅读(5670) 评论(0) 推荐(0)
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh 阅读全文
posted @ 2017-02-10 19:14 Strugglion 阅读(536) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: 解法: 建立一个大小为256整形数组,用来记录每个字符上一次出现的位置。longest记录最长的子串长度, 阅读全文
posted @ 2017-02-09 22:26 Strugglion 阅读(163) 评论(0) 推荐(0)
摘要: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 contai 阅读全文
posted @ 2017-02-09 18:58 Strugglion 阅读(246) 评论(0) 推荐(0)
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2017-02-09 16:05 Strugglion 阅读(405) 评论(0) 推荐(0)