LeetCode
leetcode算法题
coderlong
钱能解决的事情,,,我都解决不了。
展开
-
动态规划 - 分割数组的最大值
给定一个非负整数数组和一个整数 m,你需要将这个数组分成 m 个非空的连续子数组。设计一个算法使得这 m 个子数组各自和的最大值最小。注意:数组长度 n 满足以下条件:1 ≤ n ≤ 10001 ≤ m ≤ min(50, n)示例:输入:nums = [7,2,5,10,8]m = 2输出:18解释:一共有四种方法将nums分割为2个子数组。其中最好的方式是将其分...原创 2020-01-03 23:49:16 · 1174 阅读 · 0 评论 -
leetcode056_merge_intervals
Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 先把给的list按照 start排序,之后遍历选择就行了。 /** * Definitio...原创 2018-03-16 15:21:02 · 150 阅读 · 0 评论 -
leetcode055_Jump_game
/*** @author 作者 : coderlong* @version 创建时间:2018年3月16日 下午12:56:08* 类说明: 愚蠢的解法, 还是要 贪心算法*/public class leetcode055_Jump_game { public static boolean canJump2(int[] nums) { if (nums ==...原创 2018-03-16 15:22:25 · 254 阅读 · 0 评论 -
leetcode801_Mininum_SwapMakesSequencesIncreasing
title: leetcode801_Mininum_SwapMakesSequencesIncreasing date: 2018-3-20 14:18:40 categories: - leetcode tags: - leetcodeWe have two integer sequences A and B of the same non-zero le...原创 2018-03-20 13:26:56 · 875 阅读 · 0 评论 -
leetocode213_House_Roubber2
前面写过一道,在一条街道上如何抢劫的最多,这道题是那道题的继承。关键之处在于,前面的那个街道,变成了环形的。 使用java写出DP方程,dp[0] = nums[0], dp[1] = Math.max(nums[0], nums[1]) dp[i] = math.max(dp[i-2] + nums[i], dp[i - 1]), 我是直接写出了一个DPHelper,同样可以解决一条街...原创 2018-04-02 16:37:17 · 143 阅读 · 0 评论 -
leetcode221_Maximal_Square
我们在来看一道DP问题, 原题是这样的: Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.For example, given the following matrix: 1 0 1 0 0 1 0 ...原创 2018-04-02 17:22:32 · 322 阅读 · 0 评论 -
357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100...原创 2018-04-10 19:55:21 · 164 阅读 · 0 评论 -
非递归中序遍历的一点解释
递归形式的前序,中序,后序,便利大家应该都是比较熟悉的。但是,有时候,在针对一些对BST遍历过程中节点状态控制的时候,使用非递归形式的算法,往往更加有效,代码更加简洁。 1. 先把二叉树的非递归中序遍历贴出。leetcode题目public List<Integer> inorderTraversal(TreeNode root) { List<Integer>...原创 2018-04-16 16:54:30 · 641 阅读 · 0 评论 -
二叉树路径的最大值
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The pa...原创 2018-04-19 10:22:41 · 2327 阅读 · 1 评论 -
LeetCode 43. Multiply Strings
自己来实现字符串的 mul函数, 给定的字符串符合数字的要求,very simple Solution 考虑清楚中间的carry, index 就行了.class Solution { public String multiply(String num1, String num2) { if (num1.equals("0") || num2.equals("0"...原创 2018-04-26 17:03:40 · 157 阅读 · 0 评论 -
leetcode 417. Pacific Atlantic Water Flow
原题目: Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the “Pacific ocean” touches the left and top edges of the matrix and the “Atlantic ocean”...原创 2018-04-27 16:26:31 · 406 阅读 · 1 评论 -
leetcode 473. Matchsticks to Square
原题目: Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You...原创 2018-04-28 16:14:40 · 171 阅读 · 0 评论 -
leetcode 547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then ...原创 2018-05-03 10:39:58 · 286 阅读 · 0 评论 -
leetcode 802. Find Eventual Safe States
fdfg原创 2018-05-09 12:24:36 · 303 阅读 · 0 评论 -
leetcode 785. Is Graph Bipartite?
Given an undirected graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it’s set of nodes into two independent subsets AandBsuch that every edge in the...原创 2018-05-09 12:35:56 · 549 阅读 · 0 评论 -
Lettter_Case_Permutation
title: 784. Letter Case Permutation date: 2018-3-4 21:18:40 categories: - Algorithm tags: - AlgorithmGiven a string S, we can transform every letter individually to be lowercase or...原创 2018-03-05 19:57:00 · 174 阅读 · 0 评论 -
Longest-Substring-Without-Repeating-Characters
title: Longest Substring Without Repeating Characters date: 2017-10-24 22:58:49 categories: - algorithm tags: - algorithm摘要:Brute Force 正文: Approach #1 Brute Force [Time Lim...原创 2018-03-16 14:22:06 · 164 阅读 · 0 评论 -
leetcode797_all_paths_from_source_to_target
title: leetcode797_all_paths_from_source_to_target date: 2018-1-11 14:48:38 categories: - leetcode tags: - leetcodeGiven a directed, acyclic graph of N nodes. Find all possible pat...原创 2018-03-16 14:25:12 · 621 阅读 · 0 评论 -
leetcode257_BinaryTreePaths
title: leetcode257_BinaryTreePaths date: 2018-3-11 14:18:40 categories: - leetcode tags: - leetcodeGiven a binary tree, return all root-to-leaf paths.For example, given the follow...原创 2018-03-16 14:25:29 · 178 阅读 · 0 评论 -
538. Convert BST to Greater Tree
题目 Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. Exa原创 2018-01-05 22:10:26 · 177 阅读 · 0 评论 -
leetcode453_Minimum_moves_to_Equal_array
title: stringComplare date: 2017-10-26 21:00:54 categories: - java tags: - JVM - java摘要: 探秘String Stringbuffer StrignBuilder你了解String 类吗?想要了解一个类,最好的办法就是看这个类的实现源代码,String类的实现在 \jdk1.6.0原创 2017-12-18 23:07:10 · 190 阅读 · 0 评论 -
leetcode551_Student_Attendance_Record1
学生出勤记录You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A student could be rewarde原创 2018-01-09 11:36:37 · 174 阅读 · 0 评论 -
leetcode023_Generate_Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ “((()))”, “(()())”, “(())()”, “()(())”,原创 2018-03-07 16:31:45 · 209 阅读 · 0 评论 -
Max Sum of Rectangle No Larger Than K
title: 363.Max Sum of Rectangle No Larger Than K date: 2018-2-7 21:48:38 categories: - algorithm tags: - algorithm - java - leetcodeGiven a non-empty 2D matrix matrix and an原创 2018-02-07 21:30:53 · 205 阅读 · 0 评论 -
AVL平衡树详解
title: AVL平衡树删除增加操作 date: 2018-3-7 23:59:17 categories: - java tags: - java - java集合 - JDK在看MySQL索引结构的时候,就对什么B树,B+树,BST有点混淆了。 等到在遇到AVL树,JDK的HashMap实现红黑树的时候,就更加搞不明白了, 所以...原创 2018-03-07 19:38:16 · 321 阅读 · 0 评论 -
Longest-Substring-Without-Repeating-Characters
title: Longest Substring Without Repeating Characters date: 2017-10-24 22:58:49 categories: - algorithm tags: - algorithm摘要:Brute Force 正文: Approach #1 Brute Force [Time Lim...原创 2018-03-05 19:55:25 · 537 阅读 · 0 评论