- 博客(23)
- 收藏
- 关注
原创 总结几道DFS的问题
为了感谢某人花了两天给我讲明白了DFS的问题…我得赶紧把它们记下来…问题来自leetcode,问题的集锦来自https://zhuanlan.zhihu.com/p/62884431#695这道题给了一个二维数组,0表示水,1表示陆地。问连在一起的1最多有几个。a 是岛屿的数组s 是状态数组i,j代表位置def dfs(a, s, i, j, ans)://在dfs中,我们首先要修...
2019-10-13 08:57:35 431
原创 206. Reverse Linked List
#206. Reverse Linked ListReverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL这道题是把一个链表反转。/** * Definition for singly-linked...
2019-10-10 09:05:15 65
原创 104. Maximum Depth of Binary Tree
#104. Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./**...
2019-10-10 03:28:49 69
原创 1137. N-th Tribonacci Number
#1137. N-th Tribonacci NumberThe Tribonacci sequence Tn is defined as follows:T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.Given n, return the value of Tn./** * @param {numbe...
2019-10-10 00:47:36 83
原创 206. Reverse Linked List
#206. Reverse Linked ListReverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL/** * Definition for singly-linked list. * fun...
2019-10-10 00:43:08 52
原创 896. Monotonic Array
#896. Monotonic ArrayAn array is monotonic if it is either monotone increasing or monotone decreasing.An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone...
2019-10-10 00:31:28 64
原创 237. Delete Node in a Linked List
#237. Delete Node in a Linked ListWrite a function to delete a node (except the tail) in a singly linked list, given only access to that node.var deleteNode = function(node) { node.val = node.ne...
2019-10-09 23:30:49 66
原创 953. Verifying an Alien Dictionary
#953. Verifying an Alien DictionaryIn an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowe...
2019-10-09 23:26:21 83
原创 1029. Two City Scheduling
#1029. Two City SchedulingThere are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is cost...
2019-10-09 23:13:26 121
原创 696. Count Binary Substrings
#696. Count Binary SubstringsGive a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings are g...
2019-10-09 22:44:01 75
原创 1071. Greatest Common Divisor of Strings
#1071. Greatest Common Divisor of StringsFor strings S and T, we say “T divides S” if and only if S = T + … + T (T concatenated with itself 1 or more times)Return the largest string X such that X d...
2019-10-08 04:13:44 105
原创 653. Two Sum IV - Input is a BST*
#653. Two Sum IV - Input is a BSTGiven a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.这道题的意思是,给一个BST和一...
2019-10-08 03:32:43 103
原创 108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is def...
2019-10-08 02:48:11 71
原创 1185. Day of the Week
#1185. Day of the WeekGiven a date, return the corresponding day of the week for that date.The input is given as three integers representing the day, month and year respectively.Return the answer a...
2019-10-01 05:22:33 131
原创 1002. Find Common Characters
#1002. Find Common CharactersGiven an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For exa...
2019-10-01 05:22:24 68
原创 557. Reverse Words in a String III
#557. Reverse Words in a String IIIGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Inp...
2019-10-01 05:22:15 60
原创 908. Smallest Range I
#908. Smallest Range IGiven an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i].After this process, we have some array B.Return the smallest...
2019-10-01 05:22:02 100
原创 1078. Occurrences After Bigram
#1078. Occurrences After BigramGiven words first and second, consider occurrences in some text of the form “first second third”, where second comes immediately after first, and third comes immediatel...
2019-10-01 05:21:49 109
原创 1047. Remove All Adjacent Duplicates In String
#1047. Remove All Adjacent Duplicates In StringGiven a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.We repeatedly make du...
2019-10-01 05:21:37 138
原创 821. Shortest Distance to a Character
#821. Shortest Distance to a CharacterGiven a string S and a character C, return an array of integers representing the shortest distance from the character C in the string.Example 1:Input: S = “lo...
2019-10-01 05:21:26 87
原创 344. Reverse String
#344. Reverse StringWrite a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by modifying t...
2019-10-01 05:21:14 2020
原创 872. Leaf-Similar Trees
#872. Leaf-Similar TreesConsider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence./** * Definition for a binary tree node. * functi...
2019-10-01 05:21:02 50
原创 867. Transpose Matrix
#867. Transpose MatrixGiven a matrix A, return the transpose of A.The transpose of a matrix is the matrix flipped over it’s main diagonal, switching the row and column indices of the matrix.Exampl...
2019-10-01 05:20:22 119 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人