法二:利用取余规律进行数组数据按要求重排,方法简单,Accept。 1voidrotate(vector<int>&nums,intk)2{3if(nums.size() ==0|| k <=0)return;4vector<int>space(nums);5for(inti =0; i<nums.size(); i++)6nums[(i + k) % nums.size()] =space[i];7} 法三:严格按照Explanation中的步骤一步...
Input:a = "1010", b = "1011"Output:"10101" 本章主题是Array and String,所以自然就联想到了把二进制字符存放在数组中,这里涉及类型转换(从string类->int类)。然后进行两个数组逐位遍历相加。计算完成后再把int数组转为string类。 这里要考虑很多特殊情况。代码很快就能编好,但是要考虑全面,增加代码的健壮...
https://leetcode.cn/problems/find-products-of-elements-of-big-array/ 大思路并不算难想,先用二分猜答案的思想找到区间内的最小和最大数,然后通过位运算,把区间内所有数的每个二进制位,转化成对应答案的2的幂次。但区间两端不完整的数会让这道题实现极其复杂,比赛时间内调通确实是个很具挑战性的任务。这...
https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/ Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word ...
力扣leetcode-cn.com/problems/reverse-vowels-of-a-string/ 题目描述 给你一个字符串 s ,仅反转字符串中的所有元音字母,并返回结果字符串。 元音字母包括 'a'、'e'、'i'、'o'、'u',且可能以大小写两种形式出现。 示例1: 输入:s = "hello" 输出:"holle" 示例2: 输入:s = "leetcode" 输出:...
https://leetcode.com/problems/squares-of-a-sorted-array/ 3. Pattern: Fast & Slow pointers,快慢...
题目地址:https://leetcode-cn.com/problems/string-matching-in-an-array/ 题目描述 给你一个字符串数组words,数组中的每个字符串都可以看作是一个单词。请你按 任意 顺序返回words中是其他单词的子字符串的所有单词。 如果你可以删除words[j]最左侧和/或最右侧的若干字符得到word[i],那么字符串words[i]就是...
https://leetcode.cn/problems/number-of-matching-subsequences/ Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s. A subsequence of a string is a new string generated from the original string with some characters (can be none) delete...
https://leetcode-cn.com/problems/minimum-path-sum/ Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified. You should pack your words in a greedy approach; that is, pack as many words ...
845 Longest Mountain in Array 34.00% Medium 844 Backspace String Compare 45.50% Easy 843 Guess the Word 42.60% Hard 842 Split Array into Fibonacci Sequence 34.60% Medium 841 Keys and Rooms 59.70% Medium 840 Magic Squares In Grid 35.10% Easy 839 Similar String Groups 33.50% Hard 838 Push Dom...