![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
maomao_dreamhigh
这个作者很懒,什么都没留下…
展开
-
LeetCode62 Unique Paths
动态规划dp[i][j] = dp[i-1][j]+dp[i][j-1]class Solution { public int uniquePaths(int m, int n) { if(m == 0 || n == 0) return 0; if(m == 1 || n == 1) return 1; int[][] dp = ne...原创 2019-12-27 16:54:15 · 109 阅读 · 0 评论 -
LeetCode79 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically ne...原创 2019-11-26 10:09:42 · 96 阅读 · 0 评论 -
148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.这道题是Linked List的排序,但是对空间复杂度是有要求的。我首先把昨天学会的那个插入排序写上了,本来以为不会通过,没想到竟然通过了。但是这个用时竟然有603ms,很吓人。class Solution { public ListNode s...原创 2019-04-06 19:20:22 · 68 阅读 · 0 评论 -
290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.class So...原创 2019-04-06 20:39:54 · 128 阅读 · 0 评论 -
973. K Closest Points to Origin
We have a list of points on the plane. Find the K closest points to the origin (0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in any o...原创 2019-03-28 16:55:44 · 250 阅读 · 0 评论 -
75. Sort Colors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the int...原创 2019-04-02 10:59:08 · 74 阅读 · 0 评论 -
324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]…Example 1:Input: nums = [1, 5, 1, 1, 6, 4]Output: One possible answer is [1, 4, 1, 5, 1, 6].Exam...原创 2019-04-12 10:21:20 · 98 阅读 · 0 评论 -
147. Insertion Sort List
Sort a linked list using insertion sort.Algorithm of Insertion Sort:1、Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.2、At each iteration, ins...原创 2019-04-03 09:15:17 · 70 阅读 · 0 评论 -
母牛生小牛
母牛生小牛题目假设农场中成熟的母牛每年只会生1头小母牛,并且永远不会死。第一年农场只有一只成熟的母牛,从第二年开始,母牛开始生小母牛。每只小母牛3年成熟后又可以生小母牛。给定整数N,求出N年后牛的数量。【解答】所有的牛都不会死,所以第N-1年的牛会毫无损失的活到第N年。同时所有成熟的牛都会生1头小牛,那么成熟的牛数量如何估计?就是第N-3年的所有牛,到第N年肯定是成熟的牛,期间出生的牛肯定...转载 2019-09-04 08:54:26 · 1184 阅读 · 0 评论 -
Leetcode 300
关于 Arrays.binarySearch() 方法的分析在这种方法中,我们从左到右扫描数组。我们还使用一个用所有0初始化的dp数组。这个dp数组用于存储通过包含当前遇到的元素而形成的递增子序列。在遍历nums数组时,我们继续用到目前为止遇到的元素填充dp数组。对于与jth索引(nums[j])相对应的元素,我们通过使用二进制搜索(由于dp数组存储的是增加的子序列,因此可以使用二进制搜索)...转载 2019-09-10 23:33:41 · 226 阅读 · 0 评论 -
56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.今天做了一道Medium的题,竟然做出来了。不过在这个过程中我遇到了一些问题:1、list.remove()使用List中remove方法时需要注意的问题2、list集合转化为二维数组集合转数组的toArray()和toArray(T[] a方法)/**...原创 2019-04-01 10:58:58 · 93 阅读 · 0 评论 -
1013. Partition Array Into Three Parts With Equal Sum
Given an array A of integers, return true if and only if we can partition the array into three non-empty parts with equal sums.Formally, we can partition the array if we can find indexes i+1 < j w...原创 2019-03-31 20:20:12 · 424 阅读 · 0 评论 -
999. Available Captures for Rook
On an 8 x 8 chessboard, there is one white rook. There also may be empty squares, white bishops, and black pawns. These are given as characters ‘R’, ‘.’, ‘B’, and ‘p’ respectively. Uppercase charact...原创 2019-03-20 10:29:16 · 293 阅读 · 0 评论 -
Leetcode 1005. Maximize Sum Of Array After K Negations
Problem Description:Given an array A of integers, we must modify the array in the following way: we choose an i and replace A[i] with -A[i], and we repeat this process K times in total. (We may choos...原创 2019-03-16 09:54:40 · 81 阅读 · 0 评论 -
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 example, if a character occurs 3 ...原创 2019-03-16 20:09:39 · 277 阅读 · 0 评论 -
1012. Complement of Base 10 Integer
Every non-negative integer N has a binary representation. For example, 5 can be represented as “101” in binary, 11 as “1011” in binary, and so on. Note that except for N = 0, there are no leading ze...原创 2019-03-18 14:47:16 · 140 阅读 · 0 评论 -
922. Sort Array By Parity II 976. Largest Perimeter Triangle
今天做了两道easy题,我专门挑的sort种类的题,都做出来了,比较高兴了!做第二道题的时候,我用了快速排序的方法,快速排序怎么写了已经忘了,专门上网看了看,学习了学习,明天需要巩固!922. Sort Array By ParityGiven an array A of non-negative integers, half of the integers in A are odd, an...原创 2019-03-25 21:00:52 · 115 阅读 · 0 评论 -
997. Find the Town Judge
In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then:1、The town judge trusts nobody.2、Everybody (...原创 2019-03-22 16:06:04 · 74 阅读 · 0 评论 -
350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.今天做了一道easy题,和之前做的一道很类似,是II版本的,所以不是很费劲的就做出来了。class Solution { public int[] intersect(int[] nums1, int[] nums2) { if(nums1 ...原创 2019-03-29 20:39:43 · 100 阅读 · 0 评论 -
994. Rotting Oranges
In a given grid, each cell can have one of three values:the value 0 representing an empty cell;the value 1 representing a fresh orange;the value 2 representing a rotten orange.Every minute, any fr...原创 2019-03-23 14:51:40 · 142 阅读 · 0 评论 -
349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.今天,依旧做了一道easy题,是找出两个数组的交集,并且这个交集不能有重复元素。不能有重复元素,于是我想到了set集合,用set集合存储交集,然后对两个排序后的数组进行遍历。。。结果是通过了,但是花费的时间和占用的内存都太多了,这个解决方案显然是不明智的!看了D...原创 2019-03-26 21:10:07 · 167 阅读 · 0 评论 -
993. Cousins in Binary Tree
In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.Two nodes of a binary tree are cousins if they have the same depth, but have different parents.We ar...原创 2019-03-24 14:50:05 · 155 阅读 · 0 评论 -
1013. Pairs of Songs With Total Durations Divisible by 60
In a list of songs, the i-th song has a duration of time[i] seconds.Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of ...原创 2019-03-19 20:41:37 · 275 阅读 · 0 评论