![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
Crystal_ting
个人博客 limengting.site
展开
-
leetcode448 Find All Numbers Disappeared in an Array
package array;import java.util.ArrayList;public class leecode448FindNumbersNotAppear { /*448. Find All Numbers Disappeared in an ArrayGiven an array of integers where 1 ≤ a[i] ≤ n (n = size o...原创 2018-08-16 15:29:43 · 302 阅读 · 0 评论 -
628. Maximum Product of Three Numbers(Java)
Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:1、The length of the given原创 2017-09-06 21:38:18 · 266 阅读 · 0 评论 -
268. Missing Number(Java)
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in line原创 2017-08-11 17:50:06 · 332 阅读 · 0 评论 -
?[4]621. Task Scheduler(Java)
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be原创 2017-09-07 13:12:09 · 613 阅读 · 0 评论 -
[4]121. Best Time to Buy and Sell Stock(Java)
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 (ie, buy one and sell one share of the stock), desi原创 2017-09-07 15:13:12 · 321 阅读 · 0 评论 -
[4]169. Majority Element/[4]121. Best Time to Buy and Sell Stock(Java)
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always原创 2017-07-14 17:15:08 · 266 阅读 · 0 评论 -
[4]54. Spiral Matrix/59. Spiral Matrix II(Java)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should r原创 2017-09-25 00:19:28 · 389 阅读 · 0 评论 -
[3]611. Valid Triangle Numbe(Java)
Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Example 1:Inpu原创 2017-09-08 11:20:36 · 257 阅读 · 0 评论 -
[4]62. Unique Paths(Java)
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 trying to reach the botto原创 2017-09-07 21:46:00 · 319 阅读 · 0 评论 -
[3]217. Contains Duplicate(Java)
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is原创 2017-08-02 21:26:27 · 225 阅读 · 0 评论 -
661. Image Smoother(Java)
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrou原创 2017-09-06 18:36:51 · 552 阅读 · 0 评论 -
485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.原创 2017-09-04 21:33:51 · 222 阅读 · 0 评论 -
495. Teemo Attacking(Java)
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time原创 2017-09-04 22:11:21 · 331 阅读 · 0 评论 -
283. Move Zeroes(C++/Java)
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your funct原创 2017-07-11 18:32:28 · 235 阅读 · 0 评论 -
667. Beautiful Arrangement II(Java)
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, … , an原创 2017-09-04 22:25:31 · 623 阅读 · 0 评论 -
1. Two Sum/[3]167. Two Sum II - Input array is sorted(C++/Java)
1. Two SumGiven 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 u...原创 2017-06-29 23:39:10 · 309 阅读 · 0 评论 -
[3]442. Find All Duplicates in an Array/[3]448. Find All Numbers Disappeared in an Array(Java)
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra space原创 2017-09-04 21:13:20 · 250 阅读 · 0 评论 -
[3]565. Array Nesting(Java)
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 <= K < N are defined as follows:S[K] = { A[K], A[A[K]], A[A[A原创 2017-09-05 19:07:25 · 1068 阅读 · 0 评论 -
[3]122. Best Time to Buy and Sell Stock II(Java)
Say you have an array for which the i-th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one an原创 2017-07-14 16:05:30 · 373 阅读 · 0 评论 -
35. Search Insert Position(Java)
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here原创 2017-09-25 12:24:53 · 305 阅读 · 0 评论 -
?最大子列和问题(Java)/[3]53. Maximum Subarray(Java)
算法1:二重循环,复杂度O(n²)import java.util.Scanner;public class MaxSubSum1 { public static int maxSubSum(int[] array) { int thisSum, maxSum = 0; for (int i = 0; i < array.length; i ++) {原创 2017-07-30 18:53:54 · 318 阅读 · 0 评论 -
674. Longest Continuous Increasing Subsequence(Java)
Given an unsorted array of integers, find the length of longest continuous increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 3Explanation: The longest continuous increasing subsequence is [1原创 2017-09-21 22:15:50 · 285 阅读 · 0 评论 -
[4]560. Subarray Sum Equals K(Java)
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2Note: The length of the arra原创 2017-09-21 23:44:01 · 339 阅读 · 0 评论 -
[3]153. Find Minimum in Rotated Sorted Array(Java)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exist原创 2017-09-22 14:15:57 · 213 阅读 · 0 评论 -
[3]43. Multiply Strings(Java)
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:1、 The length of both num1 and num2 is < 110.2、 Both num1 and num2 contains only digits原创 2017-11-07 22:09:14 · 346 阅读 · 0 评论 -
面试常见算法3:对链表的操作
1,单/双链表的逆序package sword_to_offer_linkedlist;public class ReverseList { public static class Node { public int value; public Node next; public Node(int data) { ...原创 2018-04-18 16:45:44 · 271 阅读 · 0 评论 -
leetcode283 Move Zeros
package array;/*Given an array numswrite a function to move all 0's to the end of itwhile maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,...原创 2018-08-16 15:27:04 · 361 阅读 · 0 评论 -
leetcode169 Majority Element
package array;import java.util.HashMap;public class leetcode169MajorityElement { /* Given an array of size n, find the majority element. The majority element is the element that appear...原创 2018-08-16 15:28:34 · 261 阅读 · 0 评论 -
670. Maximum Swap(Java)
Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.Example 1:Input: 2736Output: 7236Explanation: Swa原创 2017-09-28 23:13:07 · 549 阅读 · 0 评论 -
Java刷题常见问题(Array篇)
1、如何将一个整数数组排序?int[] nums; // 已知的一个整数数组Arrays.sort(nums); // 排序2、什么时候用length,什么时候用length(),什么时候用size()?对于数组,length是数组的一个属性,用nums.length;对于字符串,用length()方法查看字符串的长度对于泛型集合,用size()方法查看这个泛型集合有多少个元素例子:publ原创 2017-09-04 14:45:53 · 547 阅读 · 0 评论 -
27. Remove Element(C++/Java)
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order原创 2017-07-04 16:05:17 · 289 阅读 · 0 评论 -
[4]78. Subsets/90. Subsets II(Java)
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,3], a solution is:[ [3], [1], [2], [1,原创 2017-09-08 17:04:59 · 371 阅读 · 0 评论 -
46. Permutations/47. Permutations II(Java)
https://discuss.leetcode.com/topic/46159/a-general-approach-to-backtracking-questions-in-java-subsets-permutations-combination-sum-palindrome-partitioning46. PermutationsGiven a collection of distinct原创 2017-09-08 18:43:26 · 275 阅读 · 0 评论 -
[4]380. Insert Delete GetRandom O(1)(Java)
Design a data structure that supports all following operations in average O(1) time.1、insert(val): Inserts an item val to the set if not already present. 2、remove(val): Removes an item val from the se原创 2017-09-26 11:51:11 · 330 阅读 · 0 评论 -
[3]48. Rotate Image(Java)
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Input: k = 3, n =原创 2017-09-06 21:13:58 · 313 阅读 · 0 评论 -
[3]118. Pascal's Triangle(Java)
Given 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]]// 错误程序class Solution { public L原创 2017-09-26 22:29:45 · 452 阅读 · 0 评论 -
64. Minimum Path Sum(Java)
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 either down or right at any原创 2017-09-28 00:53:16 · 309 阅读 · 0 评论 -
566. Reshape the Matrix(Java)
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensio原创 2017-08-11 17:09:42 · 1058 阅读 · 0 评论 -
561. Array Partition I(Java)
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl原创 2017-08-11 16:57:34 · 425 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree(Java)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode lef原创 2017-08-14 22:17:32 · 266 阅读 · 0 评论