自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 17. Letter Combinations of a Phone Number

#17. Letter Combinations of a Phone Number 这道题是一道状态更新的问题。基本的逻辑是,digits数组每一次循环,向之前得到的字符串数组增加新的字符。 var letterCombinations = function(digits) { if(digits.length===0) { return []; } le...

2020-02-21 01:18:00 87

原创 206. Reverse Linked List

#206. Reverse Linked List 把一个链表倒转 var reverseList = function(head) { if(!head){ return head; } let new_head = head; let current = null; while(head.next) { ...

2020-01-24 07:27:04 89

原创 64. Minimum Path Sum

#64. Minimum Path Sum 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. Note: You can only move eith...

2020-01-24 07:03:19 66

原创 67. Add Binary

#67. Add Binary Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = “11”, b = “1” Output...

2020-01-24 06:10:09 79

原创 328. Odd Even Linked List

#328. Odd Even Linked List Example 1: Input: 1->2->3->4->5->NULL Output: 1->3->5->2->4->NULL Example 2: Input: 2->1->3->5->6->4->7->NULL Output: 2...

2020-01-24 05:46:57 58

原创 11. Container With Most Water

#11. Container With Most Water Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at...

2020-01-24 05:20:52 51

原创 228. Summary Ranges

#228. Summary Ranges Example 1: Input: [0,1,2,4,5,7] Output: [“0->2”,“4->5”,“7”] Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range. Example 2: Input: [0,2,3,4,6,8,9] O...

2020-01-24 02:39:13 67

原创 63. Unique Paths II

#63. Unique Paths II 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 tr...

2020-01-18 05:38:11 55

原创 53. Maximum Subarray

#53. Maximum Subarray Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. 这是一个动态规划的问题。当前状态的最大值是上一个状态和上一个状态+当前值的最大值。...

2020-01-18 04:24:44 62 1

原创 459. Repeated Substring Pattern

#459. Repeated Substring Pattern 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 s...

2020-01-18 03:58:16 64

原创 56. Merge Intervals

#56. Merge Intervals 这道题是一道求并集的题。首先把给的数组数组按照数组子项的第0项大小排序。然后比较相邻的两个数组子项,前一项的第1项和后一项的第0项。 var merge = function(intervals) { if(intervals.length<2) return intervals; intervals.sort((a,b) =>...

2020-01-18 03:42:42 74

原创 20. Valid Parentheses

#20. Valid Parentheses Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. An input string is valid if: 1.Open brackets must be close...

2020-01-18 01:35:08 49

原创 205. Isomorphic Strings

#205. Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be...

2020-01-18 01:25:00 57

原创 686. Repeated String Match

#686. Repeated String Match Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1. For example, with A = “ab...

2020-01-18 00:46:24 75

原创 31. Next Permutation

#31. Next Permutation Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as ...

2020-01-17 09:18:51 125

原创 543. Diameter of Binary Tree

#543. Diameter of Binary Tree Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in ...

2020-01-17 08:32:13 61

原创 299. Bulls and Cows

#299. Bulls and Cows 这道题是给了两个数字字符串,让你分别找到对应位置数字相同的,和数字相同却不在对应位置的数字的数量。 首先遍历secret,对应位置相同的很好找。然后把位置不对应的放在map里,然后再遍历一遍。 var getHint = function(secret, guess) { let countA = 0; let countB = 0; ...

2020-01-17 08:07:16 184

原创 226. Invert Binary Tree

#226. Invert Binary Tree 这道题是把树的每一个左右子节点交换。 var invertTree = function(root) { if(root !== null) { let temp = root.left; root.left = invertTree(root.right); root.right = in...

2020-01-17 03:43:49 56

原创 1. Two Sum

#1. Two Sum 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 us...

2020-01-17 03:24:17 53

原创 88. Merge Sorted Array

88. Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and nums2 are m and n respectively...

2020-01-17 03:15:57 58

原创 总结一些树的问题

#965. Univalued Binary Tree 用DFS来解决这个问题,如果根存在,就把节点的值放在数组中,然后继续遍历它的左右子节点。最后判断数组中元素是否都相等就可以了。相同就是独一无二的树。 function dfs(root,val) { if(root) { val.push(root.val); dfs(root.left,val);...

2019-11-20 00:06:49 185

原创 总结在Rotate Sorted Array中的问题

文章目录#33. Search in Rotated Sorted Array#81. Search in Rotated Sorted Array II#153. Find Minimum in Rotated Sorted Array#154. Find Minimum in Rotated Sorted Array II #33. Search in Rotated Sorted Array...

2019-11-16 02:26:57 72

原创 总结用先序/中序/后序遍历构造树

#105. Construct Binary Tree from Preorder and Inorder Traversal 这道题是用先序(根左右)遍历和中序(左根右)遍历来构造树,这棵二叉树的根节点很好确定,就是先序的第一项。因为题目中说这棵树没有重复的项,因此根据这个根元素在中序遍历中的位置,可以分别确定先序和中序数组中左右子树的下标。然后再递归。 var buildTree = func...

2019-11-16 01:58:33 170

原创 31. Next Permutation

#31. Next Permutation 这道题是求比当前排列更大的下一个排列。 数字的排列是有顺序的,我们可以发现这个顺序是,数字从个位向前的顺序来看,后一个都应该比前一个大,如果后一个比前一个小,那么这个顺序就存在比它更大的排列。因此我们要做的第一步就是找到这个不再符合后一个比前一个大的数字的位置。 当我们找到需要重新排列的子数组arr后,下一步是在子数组中找到比arr[0]大的第一个数,交...

2019-11-15 23:55:54 49

原创 总结几道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 245

原创 206. Reverse Linked List

#206. Reverse Linked List Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL 这道题是把一个链表反转。 /** * Definition for singly-linked...

2019-10-10 09:05:15 56

原创 104. Maximum Depth of Binary Tree

#104. Maximum Depth of Binary Tree Given 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 56

原创 1137. N-th Tribonacci Number

#1137. N-th Tribonacci Number The 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 72

原创 206. Reverse Linked List

#206. Reverse Linked List Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL /** * Definition for singly-linked list. * fun...

2019-10-10 00:43:08 44

原创 896. Monotonic Array

#896. Monotonic Array An 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 50

原创 237. Delete Node in a Linked List

#237. Delete Node in a Linked List Write 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 53

原创 953. Verifying an Alien Dictionary

#953. Verifying an Alien Dictionary In 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 73

原创 1029. Two City Scheduling

#1029. Two City Scheduling There 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 108

原创 696. Count Binary Substrings

#696. Count Binary Substrings Give 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 60

原创 1071. Greatest Common Divisor of Strings

#1071. Greatest Common Divisor of Strings For 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 92

原创 653. Two Sum IV - Input is a BST*

#653. Two Sum IV - Input is a BST Given 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 87

原创 108. Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree Given 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 59

原创 1185. Day of the Week

#1185. Day of the Week Given 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 100

原创 1002. Find Common Characters

#1002. Find Common Characters Given 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 52

原创 557. Reverse Words in a String III

#557. Reverse Words in a String III Given 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 47

空空如也

空空如也

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

TA关注的人

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