![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Math
文章平均质量分 75
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Pour Water
You are given an elevation map represents as an integer arrayheightswhereheights[i]representing the height of the terrain at indexi. The width at each index is1. You are also given two integersvolumeandk.volumeunits of water will fall at indexk...原创 2022-05-15 13:36:26 · 138 阅读 · 0 评论 -
Most Profit Assigning Work
You havenjobs andmworkers. You are given three arrays:difficulty,profit, andworkerwhere:difficulty[i]andprofit[i]are the difficulty and the profit of theithjob, and worker[j]is the ability ofjthworker (i.e., thejthworker can only compl...原创 2022-05-07 11:45:14 · 242 阅读 · 0 评论 -
Find Nearest Point That Has the Same X or Y Coordinate
You are given two integers,xandy, which represent your current location on a Cartesian grid:(x, y). You are also given an arraypointswhere eachpoints[i] = [ai, bi]represents that a point exists at(ai, bi). A point isvalidif it shares the same x-...原创 2022-05-04 13:55:40 · 239 阅读 · 0 评论 -
Minimum Operations to Make a Uni-Value Grid
You are given a 2D integergridof sizem x nand an integerx. In one operation, you canaddxto orsubtractxfrom any element in thegrid.Auni-value gridis a grid where all the elements of it are equal.Returntheminimumnumber of operations to m...原创 2022-04-07 05:26:54 · 200 阅读 · 0 评论 -
Rotational Cipher
One simple way to encrypt a string is to "rotate" every alphanumeric character by a certain amount. Rotating a character means replacing it with another character that is a certain number of steps away in normal alphabetic or numerical order.For example,原创 2022-05-01 13:44:26 · 159 阅读 · 0 评论 -
Angle Between Hands of a Clock
Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the minute hand.Answers within 10-5 of the actual value will be accepted as correct.Example 1:Input: hour = 12, minutes = 30Output: 165思路:算h原创 2022-03-27 12:02:49 · 380 阅读 · 0 评论 -
Count Binary Substrings
Give a binary strings, return the number of non-empty substrings that have the same number of0's and1's, and all the0's and all the1's in these substrings are grouped consecutively.Substrings that occur multiple times are counted the number of times...原创 2022-03-20 13:51:39 · 124 阅读 · 0 评论 -
Minimum Time to Type Word Using Special Typewriter
There is a special typewriter with lowercase English letters'a'to'z'arranged in acirclewith apointer. A character canonlybe typed if the pointer is pointing to that character. The pointer isinitiallypointing to the character'a'.Each second,...原创 2022-03-20 06:12:48 · 201 阅读 · 0 评论 -
Minimum Moves to Equal Array Elements
Given an integer arraynumsof sizen, returnthe minimum number of moves required to make all array elements equal.In one move, you can incrementn - 1elements of the array by1.Example 1:Input: nums = [1,2,3]Output: 3Explanation: Only three mov...原创 2022-03-12 15:16:40 · 508 阅读 · 0 评论 -
Minimum Number of Steps to Make Two Strings Anagram
You are given two strings of the same lengthsandt. In one step you can chooseany characteroftand replace it withanother character.Returnthe minimum number of stepsto maketan anagram ofs.AnAnagramof a string is a string that contains the ...原创 2022-02-24 15:27:05 · 182 阅读 · 0 评论 -
Buddy Strings
Given two stringssandgoal, returntrueif you can swap two letters insso the result is equal togoal, otherwise, returnfalse.Swapping letters is defined as taking two indicesiandj(0-indexed) such thati != jand swapping the characters ats[i]...原创 2022-02-24 03:06:36 · 265 阅读 · 0 评论 -
Removing Minimum Number of Magic Beans
You are given an array ofpositiveintegersbeans, where each integer represents the number of magic beans found in a particular magic bag.Removeany number of beans (possibly none) from each bag such that the number of beans in each remainingnon-empty...原创 2022-02-13 12:49:48 · 220 阅读 · 0 评论 -
Remove 9
Start from integer1, remove any integer that contains9such as9,19,29...Now, you will have a new integer sequence[1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...].Given an integern, returnthenth(1-indexed) integer in the new sequence.Example 1:Inp...原创 2022-02-06 08:23:45 · 85 阅读 · 0 评论 -
Integer to English Words
Convert a non-negative integernumto its English words representation.Example 1:Input: num = 123Output: "One Hundred Twenty Three"Example 2:Input: num = 12345Output: "Twelve Thousand Three Hundred Forty Five"Example 3:Input: num = 12345..原创 2022-01-19 08:08:30 · 281 阅读 · 0 评论 -
Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2014-02-10 14:31:13 · 454 阅读 · 0 评论 -
Spiral Matrix
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原创 2014-02-10 14:17:50 · 553 阅读 · 0 评论 -
Maximum Profit of Operating a Centennial Wheel
You are the operator of a Centennial Wheel that hasfour gondolas, and each gondola has room foruptofour people. You have the ability to rotate the gondolascounterclockwise, which costs yourunningCostdollars.You are given an arraycustomersof leng...原创 2020-09-27 12:46:15 · 226 阅读 · 0 评论 -
Simplified Fractions
Given an integern, return a list of allsimplifiedfractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-ton. The fractions can be inanyorder.Example 1:Input: n = 2Output: ["1/2"]Explanation: "1/2" is the only uni...原创 2020-09-21 02:16:56 · 303 阅读 · 0 评论 -
Count All Valid Pickup and Delivery Options
Givennorders, each order consist in pickup and delivery services.Count all valid pickup/delivery possible sequences such that delivery(i) is always after ofpickup(i).Since the answermay be too large,return it modulo10^9 + 7.Example 1:Input...原创 2020-09-19 11:33:19 · 232 阅读 · 0 评论 -
Count Unhappy Friends
You are given a list ofpreferencesfornfriends, wherenis alwayseven.For each personi,preferences[i]containsa list of friendssortedin theorder of preference. In other words, a friend earlier in the list is more preferred than a friend later i...原创 2020-09-14 05:43:55 · 273 阅读 · 0 评论 -
Maximum Length of Subarray With Positive Product
Given an array of integersnums, findthe maximum length of a subarray where the product of all its elements is positive.A subarray of an array is a consecutive sequence of zero or more values taken out of that array.Returnthe maximum length of a suba...原创 2020-08-30 14:48:53 · 238 阅读 · 0 评论 -
Second Max of Array
Find the second max number in a given array.ExampleExample1:Input: [1,3,2,4]Output: 3Example2:Input: [1,1,2,2]Output: 2NoticeYou can assume the array contains at least two numbers.The second max number is the second number in a descend原创 2020-11-02 11:56:21 · 254 阅读 · 1 评论 -
Best Time to Buy and Sell Stock I
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock)...原创 2016-10-16 02:25:06 · 208 阅读 · 0 评论 -
Math 题目总结
Math的题目,其实全是数学知识,没有什么太多的算法可言。Sparse Matrix Multiplication (矩阵相乘就是所有的k,A(i,k) * B(k,j) = C(i,j) ,稀疏矩阵就是 有很多0,为了提高速度也就是如果 A(i,k) 或者B(k,j), k 从0到length,如果有0,那么这个计算就不进行了)...原创 2020-07-04 11:35:29 · 628 阅读 · 1 评论 -
Strong Password Checker
A password is considered strong if below conditions are all met:It has at least 6 characters and at most 20 characters. It must contain at least one lowercase letter, at least one uppercase letter, and at least one digit. It must NOT contain three repe原创 2020-06-27 11:59:23 · 200 阅读 · 0 评论 -
Maximum of Absolute Value Expression
Given two arrays of integers with equal lengths, return the maximum value of:|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|where the maximum is taken over all0 <= i, j < arr1.length.Example 1:Input: arr1 = [1,2,3,4], arr2 = [-1,4,5,6].原创 2020-06-18 12:56:57 · 341 阅读 · 0 评论 -
Permutation Sequence
The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123" "132" "213" "231"...原创 2014-12-20 09:18:53 · 590 阅读 · 0 评论 -
Candy Crush
This question is about implementing a basic elimination algorithm for Candy Crush.Given a 2D integer arrayboardrepresenting the grid of candy, different positive integersboard[i][j]represent different types of candies. A value ofboard[i][j] = 0repr...原创 2020-06-09 07:30:11 · 493 阅读 · 0 评论 -
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. The maximum number of consecutive 1s is 3.Note原创 2020-06-08 09:04:15 · 195 阅读 · 0 评论 -
Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there existsi, j, ksuch thatarr[i]ar原创 2016-09-13 06:16:07 · 213 阅读 · 0 评论 -
Next Greater Element III
Given a positive32-bitintegern, you need to find the smallest32-bitinteger which has exactly the same digits existing in the integernand is greater in value than n. If no such positive32-bitinteger exists, you need to return -1.Example 1:Inpu...原创 2020-06-01 11:35:14 · 177 阅读 · 0 评论 -
Find Winner on a Tic Tac Toe Game
Tic-tac-toe is playedbytwo playersAandBon a3x3grid.Here are the rules of Tic-Tac-Toe:Players take turns placing characters into empty squares (" "). The first playerAalways places "X" characters, while the second playerBalways places "O"...原创 2020-06-01 09:02:55 · 240 阅读 · 0 评论 -
Minimum Area Rectangle
Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes.If there isn't any rectangle, return 0.Example 1:Input: [[1,1],[1,3],[3,1],[3,3],[2,2]]Output: 4Ex原创 2020-06-01 08:32:49 · 251 阅读 · 0 评论 -
Rectangle Area
Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Example:Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2Output:...原创 2020-06-01 07:03:49 · 267 阅读 · 0 评论 -
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:用第一行,第一列来记录信息。然后首先略过第一行第一列,进行设置。然后再看第一行第一列是否要设置0;public class Solution { public原创 2014-02-07 05:31:50 · 597 阅读 · 0 评论 -
Find N Unique Integers Sum up to Zero
Given an integern, returnanyarray containingnuniqueintegers such that they add up to 0.Example 1:Input: n = 5Output: [-7,-1,1,3,4]Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].Example 2:Input: n = 3Output: [...原创 2020-05-28 14:14:27 · 231 阅读 · 0 评论 -
Valid number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous.原创 2014-03-02 13:45:34 · 690 阅读 · 0 评论 -
Valid Parenthesis String
Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:Any left parenthesis'('must have a corresponding right parenthesis')'...原创 2020-05-22 13:38:03 · 256 阅读 · 0 评论 -
Maximum Swap
Given a non-negative integer, you could swap two digitsat mostonce to get the maximum valued number. Return the maximum valued number you could get.Example 1:Input: 2736Output: 7236Explanation: Swap the number 2 and the number 7.Example 2:I..原创 2020-05-21 14:33:10 · 171 阅读 · 0 评论 -
Magic Squares In Grid
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbersfrom 1 to 9such that each row, column, and both diagonals all have the same sum.Given angridof integers, how many 3 x 3 "magic square" subgrids are there? (Each subgrid is contiguous)....原创 2020-05-17 07:54:46 · 138 阅读 · 0 评论