- 博客(179)
- 收藏
- 关注
原创 Leetcode 318 Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le
2017-07-28 04:13:51
329
原创 Leetcode 540 Single Element in a Sorted Array
Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once.Example 1:Input: [
2017-07-27 22:24:54
885
原创 写在搬家前一天
回到水深火热帝国主义已经一周了,这些天在新公寓拿瑜伽垫打了个地铺,过着原始人的生活。明天租了车,找了小伙伴打算把杂七杂八的东西搬过来,最后再去打扫个卫生就交房了。匹村没有江城那么热辣,却有点小江城的意味,毕竟对于我们这些苦逼的没有空调的学生来说是这样的。想了想,暑假也过了这么久了,自己做了个啥,啥都没干。对于未来的惶恐从来没有让人真的振奋。留学的日子无聊且悲惨,孤独却充斥着难过
2017-07-22 02:12:05
730
原创 Leetcode 140 Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dict
2017-07-10 10:56:50
332
原创 Leetcode 516 Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palind
2017-07-05 10:53:30
253
原创 Leetcode 449 Serialize and Deserialize BST
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be
2017-07-04 18:17:16
686
原创 Leetcode 78 Subsets
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1],
2017-07-03 20:26:54
188
原创 Leetcode 451 Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.So 'e
2017-07-03 16:50:06
180
原创 Leetcode 535 Encode and Decode TinyURL
TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.Design the encode and de
2017-07-03 15:58:56
280
原创 Leetcode 236 Lowest Common Ancestor of a Binary Tree
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 defined between two node
2017-07-03 11:15:13
192
原创 Leetcode 89 Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2017-07-03 10:49:55
244
原创 Leetcode 22 Generate Parentheses
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:[ "((()))", "(()())", "(())()", "()(())",
2017-06-21 17:36:26
206
原创 Leetcode 419 Battleships in a Board
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:You receive a valid
2017-06-21 16:09:44
208
原创 Leetcode 378 Kth Smallest Element in a Sorted Matrix
Leetcode 375 这个问题和375是同一个问题可以用完全一样的方法来做Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is
2017-06-21 13:17:51
202
原创 Leetcode 373 Find K Pairs with Smallest Sums
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from the first array and one element from the second a
2017-06-21 10:57:09
283
原创 Leetcode 49 Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]将string 按照an
2017-06-21 10:03:29
165
原创 Leetcode 79 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically
2017-06-20 22:28:39
177
原创 Leetcode 17 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st
2017-06-20 19:41:06
286
原创 Leetcode 270 Closest Binary Search Tree Value
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:Given target value is a floating point.You are guaranteed to have only o
2017-06-20 13:12:13
292
原创 Leetcode 8 String to Integer (atoi)
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 and ask yourself what are the possible input ca
2017-06-17 23:14:22
176
原创 Leetcode 187 Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2017-06-17 18:08:32
236
原创 Leetcode 384 Shuffle an Array
Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3.int[] nums = {1,2,3};Solution solution = new Solution(nums);// Shuffle the array [1,2,3] and return
2017-06-16 18:01:51
218
原创 Leetcode 146 LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key
2017-06-16 14:46:43
278
原创 Leetcode 239 Sliding Window Maximum
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 k numbers in the window. Each time the sliding window
2017-06-15 19:58:04
146
原创 Leetcode 125 Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a
2017-06-15 18:08:55
184
原创 Leetcode 167 Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number
2017-06-15 17:42:47
169
原创 Morris traversal
第一次看到traversal可以在O(1)的space里面完成,就是利用的 Morris traversal 基本思想在于:使当前节点左子树的最右节点的右指针指向当前节点所以在遍历完之后能回到当前节点 private void inorder(TreeNode root) { TreeNode node = root; while (node != nu
2017-06-15 17:20:54
491
原创 Leetcode 501 Find Mode in Binary Search Tree
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node c
2017-06-15 15:44:19
219
原创 Letcode 98 Validate Binary Search Tree
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 nodes with keys less than the node's key.Th
2017-06-15 15:14:42
230
原创 Leetcode 159 Longest Substring with At Most Two Distinct Characters
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.使用双指针。要求最多只有两个字母,那么在遇到新的字
2017-06-15 14:33:06
191
原创 Leetcode 158 Read N Characters Given Read4 II - Call multiple times
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the
2017-06-15 11:34:12
311
原创 Leetcode 157 Read N Characters Given Read4
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the
2017-06-15 11:01:03
333
原创 Leetcode 380 Insert Delete GetRandom O(1)
Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present.remove(val): Removes an item val from the
2017-06-13 17:09:53
252
原创 Leetcode 15 3Sum
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 zero.Note: The solution set must not contain
2017-06-13 10:53:07
145
原创 Leetcode 334 Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar
2017-06-12 14:32:35
202
原创 Leetcode 138 Copy List with Random Pointer
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 of the list.一开始没懂啥是random pointer。。其实就是除了n
2017-06-12 14:02:38
184
原创 Leetcode 208 Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.trie 就是prefix tree 用word的前缀进行索引的tree基本思路是每一个node都有
2017-06-12 11:44:43
198
原创 Leetcode 67 Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".一个二进制加法的问题,按照原理写出了就行。注意carrybit。public class Solution { public String addBin
2017-06-12 10:48:54
156
原创 Leetcode 152 Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest
2017-06-09 18:07:19
236
原创 Leetcode 309 Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2017-06-09 11:30:12
211
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人