原文链接: https://leetcode-cn.com/problems/split-two-strings-to-make-palindrome 英文原文You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a …
标签详情
双指针 分类
原文链接: https://leetcode-cn.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number 英文原文You are given a string num, representing a large integer, and an integer k. We call some integer wonderful if it is a permutation of the digits in num …
原文链接: https://leetcode-cn.com/problems/maximum-distance-between-a-pair-of-values 英文原文You are given two non-increasing 0-indexed integer arrays nums1 and nums2. A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.lengt…
原文链接: https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array 英文原文The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1,5), (2,3), and (4,4), the …
原文链接: https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-string-balanced 英文原文You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'. A string is …
原文链接: https://leetcode-cn.com/problems/reverse-prefix-of-word 英文原文Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character c…
原文链接: https://leetcode-cn.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference 英文原文You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of…
原文链接: https://leetcode-cn.com/problems/compress-string-lcci 英文原文Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string woul…
原文链接: https://leetcode-cn.com/problems/remove-duplicate-node-lcci 英文原文Write code to remove duplicates from an unsorted linked list. Example1: Input: [1, 2, 3, 3, 2, 1] Output: [1, 2, 3] Example2: Input: [1, 1, 1, 1, 2] Output: [1, 2] Note: The length…
原文链接: https://leetcode-cn.com/problems/palindrome-linked-list-lcci 英文原文Implement a function to check if a linked list is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: Could you do it in O(n) t…
原文链接: https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci 英文原文Given two (singly) linked lists, determine if the two lists intersect. Return the inter­ secting node. Note that the intersection is defined based on reference, not …
原文链接: https://leetcode-cn.com/problems/linked-list-cycle-lcci 英文原文Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop. Circular linked list: A (corrupt) linked list in which a node's next pointer po…
原文链接: https://leetcode-cn.com/problems/smallest-difference-lcci 英文原文Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference. Example: Input: {1, 3, 15, 11, …
原文链接: https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof 中文题目输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10000 通过代码 高赞题解方法一:递归法解题思路: 利用递归: 先走至链表末端,回溯时依次将节点值加入列表 ,这样就可以实现链表值的倒序输出。 Python …
原文链接: https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof 中文题目输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数在数组的前半部分,所有偶数在数组的后半部分。 示例: 输入:nums = [1,2,3,4] 输出:[1,3,2,4] 注:[3,1,2,4] 也是正确的答案之一。 提示: 0 <= nums.length <= …
原文链接: https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof 中文题目输入一个链表,输出该链表中倒数第k个节点。为了符合大多数人的习惯,本题从1开始计数,即链表的尾节点是倒数第1个节点。 例如,一个链表有 6 个节点,从头节点开始,它们的值依次是 1、2、3、4、5、6。这个链表的倒数第 3 个节点是值为 4 的节点。 示例: 给定一个链表: 1->2->3->4->5, 和 k = 2. …
原文链接: https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof 中文题目输入一个递增排序的数组和一个数字s,在数组中查找两个数,使得它们的和正好是s。如果有多对数字的和等于s,则输出任意一对即可。 示例 1: 输入:nums = [2,7,11,15], target = 9 输出:[2,7] 或者 [7,2] 示例 2: 输入:nums = [10,26,30,31,47,60], target = 40 输出:[1…
原文链接: https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof 中文题目输入一个正整数 target ,输出所有和为 target 的连续正整数序列(至少含有两个数)。 序列内的数字由小到大排列,不同序列按照首个数字从小到大排列。 示例 1: 输入:target = 9 输出:[[2,3,4],[4,5]] 示例 2: 输入:target = 15 输出:[[1,2,3,4,5],[4,5,6],[7…
原文链接: https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof 中文题目输入两个链表,找出它们的第一个公共节点。 如下面的两个链表: 在节点 c1 开始相交。 示例 1: 输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3 输出:Reference of …
原文链接: https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof 中文题目输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。为简单起见,标点符号和普通字母一样处理。例如输入字符串"I am a student. ",则输出"student. a am I"。 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 2: 输入: " hello world! " …
原文链接: https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof 中文题目字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。 示例 1: 输入: s = "abcdefg", k = 2 输出: "cdefgab" 示例 2: 输入: s = "lrloseumgh", …
原文链接: https://leetcode-cn.com/problems/sub-sort-lcci 英文原文Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest suc…
原文链接: https://leetcode-cn.com/problems/one-away-lcci 英文原文There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edi…
原文链接: https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci 英文原文Implement an algorithm to find the kth to last element of a singly linked list. Return the value of the element. Note: This problem is slightly different from the original one …
原文链接: https://leetcode-cn.com/problems/partition-list-lcci 英文原文Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of …
原文链接: https://leetcode-cn.com/problems/sorted-merge-lcci 英文原文You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order. Initially the number of elements in A and…
原文链接: https://leetcode-cn.com/problems/continuous-median-lcci 英文原文Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. Median is the middle value in an ordered integ…
原文链接: https://leetcode-cn.com/problems/pairs-with-sum-lcci 英文原文Design an algorithm to find all pairs of integers within an array which sum to a specified value. Example 1: Input: nums = [5,6,5], target = 11 Output: [[5,6]] Example 2: Input: nums = [5…
原文链接: https://leetcode-cn.com/problems/2vYnGI 英文原文 中文题目小扣在秋日市集选择了一家早餐摊位,一维整型数组 `staple` 中记录了每种主食的价格,一维整型数组 `drinks` 中记录了每种饮料的价格。小扣的计划选择一份主食和一款饮料,且花费不超过 `x` 元。请返回小扣共有多少种购买方案。 注意:答案需要以 1e9 + 7 (1000000007) 为底取模,如:计算初始结果为:1000000008,请返回 1 示例 1: 输入:stapl…
原文链接: https://leetcode-cn.com/problems/4xy4Wx 英文原文 中文题目小力将 N 个零件的报价存于数组 `nums`。小力预算为 `target`,假定小力仅购买两个零件,要求购买零件的花费不超过预算,请问他有多少种采购方案。 注意:答案需要以 1e9 + 7 (1000000007) 为底取模,如:计算初始结果为:1000000008,请返回 1 示例 1: 输入:nums = [2,5,3,5], target = 6 输出:1 解释:预算内仅能购买 …