随笔分类 -  dfs backtracking

60. Permutation Sequence
摘要:https://leetcode.com/problems/permutation-sequence/discuss/22507/%22Explain-like-I'm-five%22-Java-Solution-in-O(n) https://www.youtube.com/watch?v=xdvPD1IiyUM The set [1,2,3,...,n] contains a to... 阅读全文

posted @ 2018-11-09 10:46 猪猪🐷

351. Android Unlock Patterns
摘要:带返回值的recursion, dfs 阅读全文

posted @ 2018-11-09 06:39 猪猪🐷

267. Palindrome Permutation II
摘要:Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form. Example 1: Input: "aabb" Output: ["abba", "ba... 阅读全文

posted @ 2018-11-09 06:39 猪猪🐷

248. Strobogrammatic Number III
摘要:(3)找出1-650中所有的ambiguous number,定义:如果把一个数upside down还是一个有效数的话,这个数就是ambiguous,比如19 -> 61, follow up找到1-n中的这种数 A strobogrammatic number is a number that looks the same when rotated 180 degrees (look... 阅读全文

posted @ 2018-11-08 16:44 猪猪🐷

294. Flip Game II
摘要:You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". The g... 阅读全文

posted @ 2018-11-06 11:55 猪猪🐷

698. Partition to K Equal Sum Subsets
摘要:带返回值的dfs recursion 阅读全文

posted @ 2018-11-06 09:34 猪猪🐷

37 Sudoku Solver
摘要:two things: 带返回值的dfs recursion if(board[3 * (row / 3) + i / 3][ 3 * (col / 3) + i % 3] != '.' && board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] = 阅读全文

posted @ 2018-11-06 09:34 猪猪🐷

425. Word Squares
摘要:Given a set of words (without duplicates), find all word squares you can build from them. A sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤... 阅读全文

posted @ 2018-11-06 09:29 猪猪🐷

797. All Paths From Source to Target
摘要:Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follows: the nodes are 0, 1, ..., graph.length - 1. ... 阅读全文

posted @ 2018-11-06 09:28 猪猪🐷

254. Factor Combinations
摘要:Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possible combinations of its factors. Note: 1. You ma... 阅读全文

posted @ 2018-11-06 09:27 猪猪🐷

291. Word Pattern II
摘要:The method startsWith() is used for checking prefix of a String. It returns a boolean value true or false based on whether the specified string is pre 阅读全文

posted @ 2018-11-06 09:25 猪猪🐷

51 N-Queens
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.  Given an integer n, return all distinct solutions to the n-queens puzzle. Each... 阅读全文

posted @ 2018-11-06 09:23 猪猪🐷

437. Path Sum III
摘要:You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t 阅读全文

posted @ 2018-08-28 20:15 猪猪🐷

93. Restore IP Addresses
摘要:public String substring(int startIndex): This method returns new String object containing the substring of the given string from specified startIndex 阅读全文

posted @ 2018-08-28 20:07 猪猪🐷

求只包含素数的数组里面所有元素所有可能的乘积
摘要:not tested yet 阅读全文

posted @ 2018-08-11 04:30 猪猪🐷

permutation II
摘要:example: 1 1 1 2 for the first pos, we can chose 1 and 2 , skip the two 1s in the middle , the way we skip these 1s is within the for loop, we only ad 阅读全文

posted @ 2018-08-11 04:29 猪猪🐷

282 Expression Add Operators
摘要:Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the d 阅读全文

posted @ 2018-08-10 15:03 猪猪🐷

491 Increasing Subsequences
摘要:Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing su 阅读全文

posted @ 2018-08-10 14:46 猪猪🐷

211 Add and Search Word - Data structure design
摘要:Design a data structure that supports the following two operations: search(word) can search a literal word or a regular expression string containing o 阅读全文

posted @ 2018-08-09 18:39 猪猪🐷

212. Word Search II
摘要:再尝试用 isWord boolean 的方式创建 trienode , 做下这道题。 Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be c 阅读全文

posted @ 2018-08-09 17:28 猪猪🐷

导航