[LeetCode] 186. Reverse Words in a String II

2017-11-04
阅读 2 分钟
2.1k
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain leading or trailing spaces and the words are always separated by a single space. For example, Given s = "the sky is blue", return "blue is sky the". C...

[LeetCode] 273. Integer to English Words

2017-11-04
阅读 2 分钟
2.1k
Convert a non-negative integer to its english words representation.Given input is guaranteed to be less than 231 - 1. For example,

[LeetCode] 419. Battleships in a Board

2017-11-03
阅读 2 分钟
2.3k
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 board, made of only battleships or empty slots.Battleships can only be placed horizontally or vertical...

Basic Heap Internal Operations

2017-10-30
阅读 3 分钟
1.7k
When to use?The element need to be moved up to maintain the heap's property, for example, when offering a new element into the heap.How?Compare the element with it's parent, move it up when necessary. Do this until the element does not need to be moved.

[LeetCode] 23. Merge k Sorted Lists

2017-10-30
阅读 2 分钟
1.7k
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

[LeetCode] Repeated Substring Pattern

2017-08-08
阅读 2 分钟
2.6k
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 may assume the given string consists of lowercase English letters only and its length will not exceed 10000. Example 1: Input: "abab" Output: True Expla...

[LeetCode] Set Matrix Zeroes

2017-07-08
阅读 2 分钟
1.5k
Given a m x n matrix, if an element is 0, set its entire row andcolumn to 0. Do it in place.

[LeetCode] Implement strStr()

2017-06-24
阅读 1 分钟
1.2k
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Brute Force

[LeetCode] Valid Parentheses

2017-06-22
阅读 2 分钟
2k
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.

[LeetCode] Two Sum

2017-06-22
阅读 2 分钟
1.9k
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 exactly one solution, and you may not use the same element twice.

[LeetCode] Minimum Absolute Difference in BST

2017-06-20
阅读 1 分钟
2k
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.

[LeetCode] Search for a Range

2017-06-20
阅读 2 分钟
1.7k
Given an array of integers sorted in ascending order, 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 in the array, return [-1, -1]. For example, Given [5, 7, 7, 8, 8, 10] and target va...

[LeetCode] Search in Rotated Sorted Array

2017-06-20
阅读 2 分钟
1.8k
Suppose an array sorted in ascending order 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). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in the array.

[LeetCode] Word Search

2017-06-17
阅读 3 分钟
1.5k
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 neighboring. The same letter cell may not be used more than once.

[LeetCode] Generate Parentheses

2017-06-17
阅读 2 分钟
2.3k
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

[LeetCode] Find Bottom Left Tree Value

2017-06-16
阅读 1 分钟
2.4k
Given a binary tree, find the leftmost value in the last row of the tree.

[LeetCode] Pacific Atlantic Water Flow

2017-06-16
阅读 3 分钟
2.2k
Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" touches the right and bottom edges. Water can only flow in four directions (up, down, left, or right) ...

[LeetCode] Nested List Weight Sum

2017-06-16
阅读 3 分钟
2.7k
Given a nested list of integers, return the sum of all integers in the list weighted by their depth.

[LeetCode] Populating Next Right Pointers in Each Node

2017-06-15
阅读 2 分钟
1.5k
Given a binary tree {代码...} Initially, all next pointers are set to NULL.

[LeetCode] Unique Paths

2017-06-15
阅读 3 分钟
1.7k
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique pat...

[LeetCode] Walls and Gates

2017-06-14
阅读 2 分钟
1.8k
You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an obstacle. 0 - A gate. INF - Infinity means an empty room. We use the value 231 - 1 = 2147483647 to represent INF as you may assume that the distance to a gate is less than 2147483647. Fill each empty roo...

[LeetCode] Minimum Path Sum

2017-06-14
阅读 2 分钟
1.8k
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.

[LeetCode] Shortest Distance from All Buildings

2017-06-13
阅读 3 分钟
2.2k
Given a 2D grid, each cell is either a wall 2, an house 1 or empty 0 (the number zero, one, two), find a place to build a post office so that the sum of the distance from the post office to all the houses is smallest. Return the smallest sum of distance. Return -1 if it is not possible.

[LeetCode] Convert Sorted List to Binary Search Tree

2017-06-13
阅读 2 分钟
2.2k
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

[LeetCode]Construct Binary Tree from Preorder Inorder Traversal

2017-06-11
阅读 4 分钟
2.4k
Given preorder and inorder traversal of a tree, construct the binary tree.