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中的步骤一步...
代码: 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+...
这里就给出了解决方案,用一个HashSet集合来作为一个滑动窗口来检查字符串,可以降低我们的复杂度,那么突破点也就在这。 A sliding window is an abstract concept commonly used in array/string problems. 那么滑动窗口多用来解决一些数组或者字符串的问题,是一个抽象的概念 Back to our problem. We use HashSet ...
题目地址: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...
import OrderedDict from typing import List from Utility.Timeit import Timeit """ https://leetcode.cn/problems/expressive-words/description/ """ class Solution1: def expressiveWords(self, s: str, words: List[str]) -> int: # separtion for each words to array count = 0 str_array = self...
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...
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...
String (*)https://leetcode.com/problems/string-compression/ https://leetcode.com/problems/last-substring-in-lexicographical-order/ Remove Duplicate (*)https://leetcode.com/problems/remove-duplicates-from-sorted-array/ https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ ...