自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(568)
  • 收藏
  • 关注

原创 635. Design Log Storage System

635. Design Log Storage System方法:方法:discussion:https://leetcode.com/problems/design-log-storage-system/discuss/105049/C++-easy-to-understand-solution思路:class LogSystem {public: unordered_map...

2019-07-08 03:42:21 373

原创 923. 3Sum With Multiplicity

923. 3Sum With Multiplicity方法0: dfs, TLE方法1: two pointersGiven an integer array A, and an integer target, return the number of tuples i, j, k such that i < j < k and A[i] + A[j] + A[k] == targ...

2019-07-07 05:21:43 243

原创 773. Sliding Puzzle

773. Sliding Puzzle方法1: bfsComplexityOn a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.A move consists of choosing 0 and a 4-directional...

2019-07-07 04:29:34 276

原创 684. Redundant Connection

684. Redundant Connection方法1:ComplexityIn this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinc...

2019-07-07 03:21:15 173

原创 773. Sliding Puzzle

On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.Th...

2019-07-07 02:45:50 261

原创 924. Minimize Malware Spread

924. Minimize Malware Spread方法1: union findIn a network of nodes, each node i is directly connected to another node j if and only if graph[i][j] = 1.Some nodes initial are initially infected by malw...

2019-07-06 11:35:33 145

原创 609. Find Duplicate File in System

609. Find Duplicate File in System方法1: hashGiven a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate...

2019-07-06 01:56:57 99

原创 1053. Previous Permutation With One Swap

1053. Previous Permutation With One Swap方法1:Given an array A of positive integers (not necessarily distinct), return the lexicographically largest permutation that is smaller than A, that can be made...

2019-07-03 13:15:03 182

原创 278. First Bad Version

278. First Bad Version方法1: binary searchYou are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Sin...

2019-07-02 10:46:42 76

原创 409. Longest Palindrome

409. Longest Palindrome方法1:易错点:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive...

2019-07-01 07:45:03 141

原创 557. Reverse Words in a String III

557. Reverse Words in a String III方法1: two pointersGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order....

2019-07-01 04:10:29 102

原创 748. Shortest Completing Word

748. Shortest Completing Word方法1:Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string l...

2019-06-30 04:47:33 152

原创 422. Valid Word Square

422. Valid Word Square方法1:易错点:Given a sequence of words, check whether it forms a valid word square.A sequence of words forms a valid word square if the kth row and column read the exact same string...

2019-06-29 12:22:40 180

原创 722. Remove Comments

722. Remove Comments方法1:Given a C++ program, remove comments from it. The program source is an array where source[i] is the i-th line of the source code. This represents the result of splitting the o...

2019-06-29 08:57:52 166

原创 616. Add Bold Tag in String

616. Add Bold Tag in StringGiven a string s and a list of strings dict, you need to add a closed pair of bold tag and to wrap the substrings in s that exist in dict. If two such substrings overlap,...

2019-06-29 05:18:30 281

原创 758. Bold Words in String

758. Bold Words in String方法1: two pointers方法2: hashsetGiven a set of keywords words and a string S, make all appearances of all keywords in S bold. Any letters between and tags become bold.The ret...

2019-06-29 04:04:40 384

原创 527. Word Abbreviation

527. Word Abbreviation方法1:ComplexityGiven an array of n distinct non-empty strings, you need to generate minimal possible abbreviations for every word following rules below.Begin with the first char...

2019-06-28 13:33:11 262

原创 482. License Key Formatting

482. License Key Formatting方法1:易错点:You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes.Gi...

2019-06-27 12:41:04 118

原创 737. Sentence Similarity II

737. Sentence Similarity II方法1: union findGiven two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar....

2019-06-25 13:23:12 182

原创 734. Sentence Similarity

734. Sentence Similarity方法1: hash table易错点:Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar...

2019-06-25 12:39:09 125

原创 739. Daily Temperatures

739. Daily Temperatures方法1: monotonic stackGiven a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temp...

2019-06-25 06:20:21 84

原创 582. Kill Process

582. Kill Process方法1: bfs方法2: recursionGiven n processes, each process has a unique PID (process id) and its PPID (parent process id).Each process only has one parent process, but may have one or mo...

2019-06-24 10:24:41 188

原创 114. Flatten Binary Tree to Linked List

114. Flatten Binary Tree to Linked List方法1: recursion方法2: iterativeGiven a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 ...

2019-06-24 09:53:30 83

原创 404. Sum of Left Leaves

404. Sum of Left Leaves方法1: recursion易错点:Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with v...

2019-06-24 08:23:51 85

原创 513. Find Bottom Left Tree Value

513. Find Bottom Left Tree Value方法1: dfsGiven a binary tree, find the leftmost value in the last row of the tree.Example 1:Input:2/ 1 3Output:1Example 2:Input: 1 / \ 2 3 / /...

2019-06-24 03:43:38 86

原创 Coin change with limitation

vector nums{1, 2, 4, 7};vector limits {1, 3, 1, 7};int target = 7;/****************************************************************************** Online C++ Compiler....

2019-06-23 14:03:27 115

原创 509. Fibonacci Number

509. Fibonacci NumberThe Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. Th...

2019-06-20 04:23:05 86

原创 Sieve of Eratosthenes solution

Sieve of Eratosthenes solution方法1: Sieve of Eratosthenes solutionComplexityCount the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 ...

2019-06-20 04:21:26 166

原创 705. Design HashSet

705. Design HashSet方法1:方法2:Design a HashSet without using any built-in hash table libraries.To be specific, your design should include these functions:add(value): Insert a value into the HashSet.c...

2019-06-19 08:22:51 119

原创 706. Design HashMap

706. Design HashMap方法1:vectorDesign a HashMap without using any built-in hash table libraries.To be specific, your design should include these functions:put(key, value) : Insert a (key, value) pair...

2019-06-19 08:17:38 152

原创 829. Consecutive Numbers Sum

829. Consecutive Numbers Sum方法1:Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers?Example 1:Input: 5Output: 2Explanation: 5 = 5 = 2 + 3Example 2...

2019-06-19 08:06:51 160

原创 819. Most Common Word

819. Most Common Word方法1: hash易错点:Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word tha...

2019-06-19 07:48:36 136

原创 974. Subarray Sums Divisible by K

974. Subarray Sums Divisible by K方法1: hash tableGiven an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.Example 1:Input: A = [4,5,0,-2,-3...

2019-06-19 06:56:54 81

原创 410. Split Array Largest Sum

410. Split Array Largest Sum方法1: dynamic programmingComplexityGiven an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. W...

2019-06-19 06:27:43 126

原创 439. Ternary Expression Parser

439. Ternary Expression Parser方法1: stackGiven a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is ...

2019-06-19 05:05:20 144

原创 937. Reorder Log Files

937. Reorder Log Files方法1:ComplexityYou have an array of logs. Each log is a space delimited string of words.For each log, the first word in each log is an alphanumeric identifier. Then, either:E...

2019-06-19 02:36:31 139

原创 331. Verify Preorder Serialization of a Binary Tree

331. Verify Preorder Serialization of a Binary Tree# # # #方法1: recursion方法2: stackOne way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the ...

2019-06-18 14:28:05 118

原创 1091. Shortest Path in Binary Matrix

@1091. Shortest Path in Binary Matrix方法1: bfs方法2: dfs, TLEIn an N by N square grid, each cell is either empty (0) or blocked (1).A clear path from top-left to bottom-right has length k if and only i...

2019-06-16 13:54:58 446

原创 1092. Shortest Common Supersequence

1092. Shortest Common Supersequence方法1:Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If multiple answers exist, you may return any of them....

2019-06-16 13:42:27 380

原创 922. Sort Array By Parity II

922. Sort Array By Parity II方法1: partition + two pointersComplexityGiven an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even.Sort the array so t...

2019-06-16 10:22:16 117

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除