随笔分类 -  leetcode

摘要:问题: 给定字符串s,和可进行交换的index对数组。 对字符串s的各个位置index,可根据交换数组所示的两两交换(次数不限),求进行交换后,可得最小的字符串。 Example 1: Input: s = "dcab", pairs = [[0,3],[1,2]] Output: "bacd" E 阅读全文
posted @ 2020-06-20 15:22 habibah_chang
摘要:问题: 给定数组arr2,所含元素唯一, 给定数组arr1,对arr1排序,使得arr1的元素相对顺序为arr2的顺序,不存在于arr2中的元素,按照升序排列。 Example 1: Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9, 阅读全文
posted @ 2020-06-20 09:20 habibah_chang
摘要:问题: 给定一个数组,使用对数组元素减-1的方式,使得数组成为一个zigzag锯形数组。 求最少减的数量 Example 1: Input: nums = [1,2,3] Output: 2 Explanation: We can decrease 2 to 0 or 3 to 1. Example 阅读全文
posted @ 2020-06-14 14:32 habibah_chang
摘要:问题: 给定一组学生身高,要对其进行身高排序,从低到高。 求最少要移动几个学生的位置。 Example 1: Input: heights = [1,1,4,2,1,3] Output: 3 Explanation: Current array : [1,1,4,2,1,3] Target arra 阅读全文
posted @ 2020-06-14 12:56 habibah_chang
摘要:问题: 给定一个字符串数组,和一个字典字符串, 若字符串数组中的一个字符串中的所有字符,能够在字典字符串中一一对应找到(字典中每个字符只能用一次),则返回这个字符串的长度。 最终返回满足条件的所有字符串长度之和。 Example 1: Input: words = ["cat","bt","hat" 阅读全文
posted @ 2020-06-14 12:32 habibah_chang
摘要:问题: 给定一个0,1组成的数组,前 i 个元素组成二进制数,若该二进制数能被5整除,返回true,否则返回false 求出这个数组前 i 个元素(i=0~size()-1)的结果数组。 Example 1: Input: [0,1,1] Output: [true,false,false] Exp 阅读全文
posted @ 2020-06-13 13:15 habibah_chang
摘要:问题: 给定一个字符串s, 和一个字串操作数组queries [i, j, k] 即对字符串s的i~j字符组成的子串,进行重新排列,且可从中最多(up to)选取k个字母,替换成任意字母, 使得子串能够成为回文字符串。 如果可以返回true,否则返回false。 Example : Input: s 阅读全文
posted @ 2020-06-13 12:19 habibah_chang
摘要:问题: 给定数组,如果刚好将数组分成三段,使得每一段的和相等,则返回true,否则返回false Example 1: Input: A = [0,2,1,-6,6,-7,9,1,2,0,1] Output: true Explanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 阅读全文
posted @ 2020-06-13 11:01 habibah_chang
摘要:问题: 给出一列歌曲所花时间的数组。 求任意两首歌合起来时间是60分钟的倍数的组队pair数。 Example 1: Input: [30,20,150,100,40] Output: 3 Explanation: Three pairs have a total duration divisibl 阅读全文
posted @ 2020-06-07 14:53 habibah_chang
摘要:问题: 给出一个数组,和一个目标值target 求一个数值value,将数组中所有>value的数换成value后,使得数组和最接近target Example 1: Input: arr = [4,9,3], target = 10 Output: 3 Explanation: When usin 阅读全文
posted @ 2020-06-07 13:34 habibah_chang
摘要:问题: 给定一个航班预定列表,每一项为 [i, j, k],意思是从 i ~ j 航班,每个航班都需要预定k个座位。 一共有n个航班,即 1<=i<=j<=n,求满足这个列表的航班1~n的座位数列表。 Example 1: Input: bookings = [[1,2,10],[2,3,20],[ 阅读全文
posted @ 2020-06-07 11:15 habibah_chang
摘要:问题: 给定一个数组,求交换其中两个元素,使得到数组全部元素组成下一个较小的数值 Example 1: Input: [3,2,1] Output: [3,1,2] Explanation: Swapping 2 and 1. Example 2: Input: [1,1,5] Output: [1 阅读全文
posted @ 2020-06-06 13:02 habibah_chang
摘要:问题: 给定一个每分钟来客数量的数组,和一个同一时刻店主是否松懈的数组, 如果店主松懈:1,那么那一分钟的来客满意度为0,否则满意度=来客数量。 店主有一技巧可使得,即使店主松懈,来客也能够满足X分钟。这一技巧只能用一次, 求一段时间的最大满意度和。 Example 1: Input: custom 阅读全文
posted @ 2020-06-06 10:40 habibah_chang
摘要:问题: 给出一组字符串,求所有字符串共有的字符数组。 Example 1: Input: ["bella","label","roller"] Output: ["e","l","l"] Example 2: Input: ["cool","lock","cook"] Output: ["c","o 阅读全文
posted @ 2020-06-06 09:15 habibah_chang
摘要:问题: 给定一个数组stones代表每一块石头的位置, 每次可对两边界的两块石头调整位置,只能向非边界的位置移动。 求解,要最终使得所有的石头连续摆放(即他们的位置连续),最多和最少分别需要移动多少次? Example 1: Input: [7,4,9] Output: [1,2] Explanat 阅读全文
posted @ 2020-06-04 17:11 habibah_chang
摘要:问题: 给定国际象棋二维数组, B代表阻止,p代表可吃点,R代表起始点。 从R开始向上下左右直线移动,遇到p点,res+1。遇到B或者棋盘边界res不增不减。 求最后res的值。 Example 1: Input: [[".",".",".",".",".",".",".","."],[".",". 阅读全文
posted @ 2020-06-03 14:09 habibah_chang
摘要:问题: 给定两个数组A,B 若两个数组存在相同的数,则画一条连线,使得所画连线不得相交,最多能画多少条? Example 1: Input: A = [1,4,2], B = [1,2,4] Output: 2 Explanation: We can draw 2 uncrossed lines a 阅读全文
posted @ 2020-06-03 13:24 habibah_chang
摘要:问题: 给定数组,求两个固定长度M和L的子数组(不相交)之和最大为多少 Example 1: Input: A = [0,6,5,2,2,5,1,9,4], L = 1, M = 2 Output: 20 Explanation: One choice of subarrays is [9] wit 阅读全文
posted @ 2020-06-03 10:43 habibah_chang
摘要:问题: 给定一个数组A为某个数的各位数,和数字K,求给A组成的数字+K,所得的数字也像A做成数组返回。 Example 1: Input: A = [1,2,0,0], K = 34 Output: [1,2,3,4] Explanation: 1200 + 34 = 1234 Example 2: 阅读全文
posted @ 2020-06-02 15:06 habibah_chang
摘要:问题: 给定一个山峦分布数组,元素值代表高度。 假设score分值=两山高度和-两山距离=A[i]+A[j]-(j-i)=A[i]+A[j]+i-j 求这个分值最高是多少? Example 1: Input: [8,1,5,2,6] Output: 11 Explanation: i = 0, j 阅读全文
posted @ 2020-06-02 14:41 habibah_chang