Input:a = "1010", b = "1011"Output:"10101" 本章主题是Array and String,所以自然就联想到了把二进制字符存放在数组中,这里涉及类型转换(从string类->int类)。然后进行两个数组逐位遍历相加。计算完成后再把int数组转为string类。 这里要考虑很多特殊情况。代码很快就能编好,但是要考虑全面,增加代码的健壮...
法二:利用取余规律进行数组数据按要求重排,方法简单,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中的步骤一步...
https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/ Youare given an array of strings words and a string chars.Astring is goodifit can be formed by characters from chars(each character can only be used once).Returnthe sum of lengths of all good strings in words.Exa...
代码: publicstaticint[]plusOne(int[]digits){digits[digits.length-1]++;for(inti=digits.length-1;i>0;i--){if(digits[i]>9){digits[i-1]++;digits[i]-=10;}}if(digits[0]>9){int[]newArray=newint[digits.length+1];newArray[0]=1;digits[0]-=10;for(inti=0;i<digits.length-1;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...
var reverseVowels = function(s) { const n = s.length; const arr = Array.from(s); let i = 0, j = n - 1; while (i < j) { while (i < n && !isVowel(arr[i])) { ++i; } while (j > 0 && !isVowel(s[j])) { --j; } if (i < j) { swap(arr, i, j); ++i...
给你一个字符串数组words,数组中的每个字符串都可以看作是一个单词。请你按任意顺序返回words中是其他单词的的所有单词。 示例1: 输入:words = ["mass","as","hero","superhero"]输出:["as","hero"]解释:"as" 是 "mass" 的子字符串,"hero" 是 "superhero" 的子字符串。 ["hero","as"] 也是有效...
LeetCode - The World's Leading Online Programming Learning Platformleetcode.com/problems/find-target-indices-after-sorting-array/submissions/1090936283/ 其实这个题如果直接用sort,然后linear去找的话也可以,因为只有100个数字。而且本身还需要去sort 数字。 感觉可能是想考手写quick sort? 手写linear 的话感...
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...
尝试更多