- 博客(27)
- 收藏
- 关注
原创 Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()",
2015-11-19 15:58:39 270
原创 Word Pattern II
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-emptysubstring in str.
2015-11-19 13:54:33 704
原创 Word Pattern
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.
2015-11-19 13:21:22 330
原创 Merge Two Sorted Lists
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. 用了一个dumb head,。对于这种header不确定的list,可以用dumb header,代码会整洁不
2015-11-19 12:50:37 279
原创 Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add
2015-11-19 12:26:15 316
原创 Lowest Common Ancestor of a Binary Search Tree
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: “The lowest common ancestor is defined betw
2015-11-19 12:10:18 218
转载 Shortest Word Dsitance III
word1 and word2 can be equal //C++: 20ms class Solution { public: int shortestWordDistance(vector& words, string word1, string word2) { int n = words.size(); int p1 = -1, p2 =
2015-11-13 05:44:35 234
转载 Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you
2015-11-13 05:43:00 254
原创 Shortest Word Distance
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. For example, Assume that words = ["practice", "makes", "perfect", "coding", "
2015-11-13 04:53:55 303
原创 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe
2015-11-13 04:03:53 208
原创 Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unk
2015-11-13 03:53:28 255
原创 Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in
2015-11-13 03:29:51 211
原创 Maximum Product Subarray
public class Solution { public int maxProduct(int[] nums) { int maxValue = nums[0]; int minValue = nums[0]; int max = nums[0]; for(int i = 1; i < nums.length; i++){
2015-11-12 16:33:57 213
原创 [LeetCode] Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] ha
2015-11-12 16:13:12 171
原创 Graph Valid Tree
Problem Description: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. Fo
2015-11-12 14:44:24 295
原创 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with anot
2015-11-12 13:31:47 228
原创 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
2015-11-12 10:48:00 293
原创 Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin
2015-11-12 07:37:28 249
原创 Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], ther
2015-11-12 06:29:15 247
原创 Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5.
2015-11-11 14:41:29 208
原创 Serialize and Deserialize Binary Tree
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
2015-11-11 13:38:57 271
原创 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. Subscribe to see which companies asked this questio
2015-11-11 12:03:36 203
原创 Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found
2015-11-10 12:00:32 209
原创 【LeetCode】Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary
2015-11-08 04:26:20 197
原创 Flowing Water
输入是一个 N*N的矩阵,代表地势高度。如果下雨水流只能流去比他矮或者一样高的地势。 矩阵左边和上边是太平洋,右边和下边是大西洋。求出所有的能同时流到两个大洋的点。 For example: 12345678910 Pacific: ~Atlantic: *~ ~ ~ ~ ~ ~ ~~ 1 2 2 3 (5) *~ 3
2015-11-07 14:29:05 328
原创 [LeetCode] Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. /** * Definition for an interval. * public
2015-11-07 13:20:00 201
原创 【Leetcode】Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 简单解法:O(dividend/divisor) public class Solution { public int divide(int divide
2015-11-03 15:50:34 183
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人