随笔分类 - leetCode hot 100
摘要:Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bot
阅读全文
摘要:给定一个整数数组Arr,求解数组中连续的不相邻元素的和的最大值。例如:对于数组中的元素A1,A2,A3,A4,则需要判断A1+A3,A1+A4,A2+A4中的最大值即为所求。 状态转移方程:dp[i] = max(dp[i - 2], dp[i - 3]) + num[i] 其中,dp[i]表示打劫
阅读全文
摘要:Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Not
阅读全文
摘要:剑指offer 数组中出现超过一半的数字 https://www.cnblogs.com/MarkLeeBYR/p/9775097.html
阅读全文
摘要:剑指offer 两个链表公共节点 https://www.cnblogs.com/MarkLeeBYR/p/9774276.html
阅读全文
摘要:剑指offer 旋转数组的最小值 https://www.cnblogs.com/MarkLeeBYR/p/9777244.html
阅读全文
摘要:Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are generated so that the answer wil
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. //利用归并排序的思想 public ListNode sortList(ListNode head) { if (head == null || head.
阅读全文
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the
阅读全文
摘要:剑指offer 链表环入口 https://www.cnblogs.com/MarkLeeBYR/p/9773649.html
阅读全文
摘要:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequ
阅读全文
摘要:剑指offer 复杂链表的复制 https://www.cnblogs.com/MarkLeeBYR/p/9775184.html
阅读全文
摘要:Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linea
阅读全文
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example 1:
阅读全文
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The longes
阅读全文
摘要:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction
阅读全文
摘要:iven numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return : [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
阅读全文
摘要:/例如根节点为1,左2右3 class Solution { TreeNode prev = null; public void flatten(TreeNode root) {//先把最大的数设在root.right,然后剩下的数一个个往里加 if (root == null) return; f
阅读全文
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. public TreeNode sortedArrayToBST(int[] nums) { if (n
阅读全文
摘要:见剑指offer重建二叉树 https://www.cnblogs.com/MarkLeeBYR/p/9777253.html
阅读全文