文章 212
评论 0
浏览 119898
String - 71. Simplify Path

String - 71. Simplify Path

Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.

String - 67. Add Binary

String - 67. Add Binary

Given two binary strings, return their sum (also a binary string).

Math - 50. Pow(x, n)

Math - 50. Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n (xn).

String - 44. Wildcard Matching

String - 44. Wildcard Matching

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

DFS&BFS - 37. Sudoku Solver

DFS&BFS - 37. Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.

Array - 36. Valid Sudoku

Array - 36. Valid Sudoku

Determine if a 9x9 Sudoku board is valid.

Array - 57. Insert Interval

Array - 57. Insert Interval

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

Binary Search - 378. Kth Smallest Element in a Sorted Matrix

Binary Search - 378. Kth Smallest Element in a Sorted Matrix

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.

Array - 59. Spiral Matrix II

Array - 59. Spiral Matrix II

Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

Array - 54. Spiral Matrix

Array - 54. Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

LinkedList - 876. Middle of the Linked List

LinkedList - 876. Middle of the Linked List

Given a non-empty, singly linked list with head node head, return a middle node of linked list.

Array - 48. Rotate Image

Array - 48. Rotate Image

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).

string- 43. Multiply Strings

string- 43. Multiply Strings

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

Array - 34. Find First and Last Position of Element in Sorted Array

Array - 34. Find First and Last Position of Element in Sorted Array

Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

Array - 31. Next Permutation

Array - 31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

String - 8. String to Integer (atoi)

String - 8. String to Integer (atoi)

8.String to Integer (atoi) Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect....

Array - 16. 3Sum Closest

Array - 16. 3Sum Closest

16. 3Sum Closest Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Example: Given array nums = [-1, 2, 1, -4], and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). 思路: 给定一个数组,找出三个数的和最接近target,和15题很像,做法类似,都是对于每一位元素,用双指针找出另外两个数,更新出一个最小的结果就可以。 代码: go: f....

Array - 15. 3Sum

Array - 15. 3Sum

15. 3Sum Given an array nums of n integers, are there elements a, b, c in nums 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 duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] 思路: 找出数组中三数和的所有组合,解决思路是首先做一个排序,然后对于每一位元素,去找出剩下数组中找出两个数和当前元素三个数和为0就可以,主要要留意重复元素就不用了计算....

Tree - 450. Delete Node in a BST

Tree - 450. Delete Node in a BST

450. Delete Node in a BST Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can be divided into two stages: Search for a node to remove. If the node is found, delete the node. Note: Time complexity should be O(height of tree). Example: root = [5,3,6,2,4,null,7] key = 3 5 / \ 3 6 / \ \ 2 4 7 Given key to delete is 3. So we find the node with value 3 and de....

Tree - 687. Longest Univalue Path

Tree - 687. Longest Univalue Path

687. Longest Univalue Path 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 the root. The length of path between two nodes is represented by the number of edges between them.   Example 1: Input: 5 / \ 4 5 / \ \ 1 1 5 Output: 2   Example 2: Input: 1 / \ 4 5 / \ \ 4 4 5 Output: 2   Note: The given binary tree has not more than 10000 nodes. The height of the tree is n....

Nothing just happens, it's all part of a plan.