
leedcode_Algorithm
做过的算法题
Asteroid 325
专注自己和专注自己热爱的事。Cross my fingers for me.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
704. 二分查找
给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。示例 1:输入: nums = [-1,0,3,5,9,12], target = 9输出: 4解释: 9 出现在 nums 中并且下标为 4示例 2:输入: nums = [-1,0,3,5,9,12], target = 2输出: -1解释: 2 不存在 nums 中因此返回 -1提示:你可以假设 nums 中的所原创 2022-05-22 04:49:16 · 146 阅读 · 0 评论 -
1331|Rank Transform of an Array
Given an array of integers arr, replace each element with its rank.The rank represents how large the element is. The rank has the following rules:Rank is an integer starting from 1.The larger the element, the larger the rank. If two elements are equal,原创 2020-12-04 22:20:45 · 129 阅读 · 0 评论 -
1672|Richest Customer Wealth
1672. 最富有客户的资产总量You are given an m x n integer grid(整数网格) accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has.A customer’s wealth is the原创 2020-12-04 21:47:32 · 227 阅读 · 0 评论 -
605|Can Place Flowers(自己突然想出来错一次改一次改到包括所有情况)
605. 种花问题Suppose you have a long flowerbed in which some of the plots(n. 情节;阴谋;小块土地(plot的复数);平面图) are planted and some are not. However, flowers cannot be planted in adjacent plots(相邻的块) - they would compete for water and both would die.(竞争水并且都会死)意思就是种花不原创 2020-11-25 00:17:17 · 185 阅读 · 0 评论 -
!!!---1588|Sum of All Odd Length Subarrays(新)
Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays.A subarray is a contiguous subsequence of the array.Return the sum of all odd-length subarrays of arr.Example 1:Input: arr = [1,4,2,5,3]Output: 58Explanat原创 2020-11-23 16:13:22 · 180 阅读 · 0 评论 -
1351|Count Negative Numbers in a Sorted Matrix(数组)
计算在有序矩阵的负数个数Given a m * n matrix grid which is sorted in non-increasing order both row-wise and column-wise. (行和列的非递增顺序。)Return the number of negative numbers in grid.Example 1:Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]Output: 8E原创 2020-11-23 15:17:09 · 149 阅读 · 0 评论 -
1275|Find Winner on a Tic Tac Toe Game(数组)
找出井字棋的获胜者Tic-tac-toe(井字游戏) is played by two players A and B on a 3 x 3 grid.Here are the rules of Tic-Tac-Toe:Players take turns placing characters into empty squares (" ").The first player A always places “X” characters, while the second player B alwa原创 2020-11-20 19:25:24 · 206 阅读 · 0 评论 -
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.You may assume that nums1 has enough space (size that is equal to m + n) to h原创 2020-11-20 15:47:12 · 238 阅读 · 0 评论 -
832|Flipping an Image(数组)
832. 翻转图像Given a binary matrix(二进制矩阵) A, we want to flip(翻转) the image horizontally, then invert it, and return the resulting image.To flip an image horizontally means that each row of the image is reversed. For example, flipping [1, 1, 0] horizontally原创 2020-11-19 22:19:10 · 113 阅读 · 0 评论 -
219.|Contains Duplicate II
存在重复元素IIGiven an array of integers and an integer k, find out whether there are two distinct(不同的 明显的 清楚的) indices(n. 指数;目录(index的复数)) i and j in the array such that nums[i] = nums[j] and the absolute difference(绝对差) between i and j is at most k.(最多k)给定一原创 2020-11-19 12:24:30 · 99 阅读 · 0 评论 -
1550.| Three Consecutive Odds(数组)
存在连续三个奇数的数组Given an integer array arr, return true if there are three consecutive (adj. 连贯的;连续不断的)odd numbers in the array. Otherwise, return false.Example 1:Input: arr = [2,6,4,1]Output: falseExplanation: There are no three consecutive odds.Example原创 2020-11-19 11:57:23 · 188 阅读 · 0 评论 -
628.|Maximum Product of Three Numbers(Math.max和Arrays.sort)
Java max() 方法Java Number类Java Number类max() 方法用于返回两个参数中的最大值。语法该方法有以下几种语法格式:double max(double arg1, double arg2)float max(float arg1, float arg2)int max(int arg1, int arg2)long max(long arg1, long arg2)参数该方法接受两个原生数据类型作为参数。返回值返回两个参数中的最大值。实例publ原创 2020-11-18 16:22:35 · 121 阅读 · 0 评论 -
面试题 17.10|主要元素(摩尔投票法+数组)
package com.javaknowlege;public class mole { static int majorElement(int nums[]){ int major=nums[0]; int cnt=0; int numsSize=nums.length; for(int i=0;i<numsSize;i++){ if(cnt==0) { m转载 2020-11-18 15:49:56 · 181 阅读 · 0 评论 -
977.|Squares of a Sorted Array
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.Example 1:Input: [-4,-1,0,3,10]Output: [0,1,9,16,100]Example 2:Input: [-7,-3,2,3,11]Output: [4,9,9,49,121]原创 2020-11-13 18:42:20 · 151 阅读 · 0 评论 -
4|Median of Two Sorted Arrays
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.Follow up: The overall run time complexity should be O(log (m+n)).Example 1:Input: nums1 = [1,3], nums2 = [2]Output: 2.00000Explanation: m原创 2020-11-13 16:06:52 · 87 阅读 · 0 评论 -
第一个flag
10月份:50道easy leedcode原创 2020-10-26 21:02:24 · 136 阅读 · 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 times in all strings but not 4 times, you need原创 2020-10-26 21:00:35 · 92 阅读 · 0 评论 -
728|Self Dividing Numbers
A self-dividing number is a number that is divisible(可分的,可分割的) by every digit( 数字) it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, a self-dividing number is not allowed to contain the digi原创 2020-10-26 16:17:15 · 147 阅读 · 0 评论 -
905|Sort Array By Parity
Given an array A of non-negative(非负整数) integers, return an array consisting of all the even(奇数) elements of A, followed by all the odd(偶数) elements of A.You may return any answer array that satisfies this condition.把偶数放前面,把奇数放后面Example 1:Input: [3,1,2,原创 2020-10-25 15:27:01 · 157 阅读 · 0 评论 -
804|Unique Morse Code Words
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “a” maps to “.-”, “b” maps to “-…”, “c” maps to “-.-.”, and so on.For convenience, the full table for the 26 letters of the Englis原创 2020-10-25 11:20:56 · 99 阅读 · 0 评论 -
412|Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five outp原创 2020-10-24 10:39:56 · 106 阅读 · 0 评论 -
657.|Robot Return to Origin
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.The move sequence is represented by a string, and the character moves[i] represents原创 2020-10-24 09:06:51 · 82 阅读 · 0 评论 -
1|Two Sum
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answer原创 2020-10-20 17:32:27 · 98 阅读 · 0 评论 -
9.|Palindrome Number
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Follow up: Could you solve it without converting the integer to a string?回文数字Example 1:Input: x = 121Output: trueExample 2:Input: x =原创 2020-10-20 16:12:38 · 167 阅读 · 0 评论 -
121|Best Time to Buy and Sell Stock
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 (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.买一个股票and原创 2020-10-23 23:54:40 · 145 阅读 · 0 评论 -
771.|Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.The letters in J are guar原创 2020-10-23 21:50:01 · 149 阅读 · 0 评论 -
561|Array Partition I拆分数组
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 possible.Example 1:Input: [1,4,3,2]Output: 4Explanation: n原创 2020-10-23 14:33:09 · 127 阅读 · 0 评论 -
860.|LemonXade Change
At a lemonade stand(柠檬汁小摊), each lemonade costs $5.Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills[按规定的顺序]).Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill.原创 2020-10-22 12:10:15 · 113 阅读 · 0 评论 -
867|Transpose Matrix
Given a matrix(矩阵) A, return the transpose(转置矩阵) of A.The transpose of a matrix is the matrix flipped over(翻转) it’s main diagonal(对角线), switching the row and column indices(index,索引) of the matrix.Example 1:Input: [[1,2,3],[4,5,6],[7,8,9]]Output: [[1,原创 2020-10-22 09:28:05 · 325 阅读 · 0 评论 -
709.|To Lower Case
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.Example 1:Input: “Hello”Output: “hello”Example 2:Input: “here”Output: “here”Example 3:Input: “LOVELY”Output: “lovely”class Solution {原创 2020-10-21 15:32:39 · 131 阅读 · 0 评论 -
7|Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Note:Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function原创 2020-10-20 17:54:58 · 97 阅读 · 0 评论 -
167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be原创 2020-10-17 17:58:34 · 109 阅读 · 0 评论 -
206.|Reverse Linked List
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursively. Could you implement both?/** * Definition for singly-原创 2020-10-17 17:01:52 · 87 阅读 · 0 评论 -
217|Contains Duplicate
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 distinct.Example 1:Input: [1,2,3,1]Output: trueExam原创 2020-10-17 08:01:50 · 77 阅读 · 0 评论 -
118.|Pascal‘s Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]class Solut原创 2020-10-17 07:43:57 · 82 阅读 · 0 评论 -
200| Number of Islands
题目:Given an m x n 2d grid map of '1’s (land) and '0’s (water), return the number of islands.An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surround原创 2020-10-15 22:03:43 · 171 阅读 · 0 评论