这个结果超过28%的solution 后来发现先j--再i++ 超过42%的solution~ 神奇 442. Find All Duplicates in an Array 原题链接:https://leetcode.com/problems/find-all-duplicates-in-an-array/ 对于一个元素nums[i],数组中nums[i]-1位置的元素反转为负数,遍历过程中如果遍历到负数,说明数字i+1出现了两次 pu...
However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks. Return the least number of units of times that the CPU will take to ...
Note:You must do this in-place without making a copy of the array. Minimize the total number of operations.题目大意把数组中的0换到数组的结尾去,同时需要保证其他数字的位置不能改变。另外需要在原地进行操作。解题方法in-place的把0放到数组的最后,其他顺序不变。用两个指针。方法一:首尾指针...
https://leetcode-cn.com/problems/reorder-list/ Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list's nodes, only nodes itself may be changed. 题意 给定一个单链表 L:L0→L1→…→Ln-1...
给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。
// Solution 1: Got nothing to do with algorthms, just beware of any bugs. 代码1 //Code 1 7 Reverse Integer // #7 反转整数 描述:给定一个10进制整数,翻转它。 //#7Description: Reverse Integer | LeetCode OJ 解法1:能用整数就别用浮点,能用数值就别用字符串。
When looking for the sequence starting with 1, we have found that the sum of[1,2,3]is less than the target, then the sum of the sequence[2,3]must also be less than 9, so why do we have to follow the steps, first go[2], then go to[2,3], then go to[2,3,4]?
It must NOT contain three repeating characters in a row (“…aaa…” is weak, but “…aa…a…” is strong, assuming other conditions are met). Write a function strongPasswordChecker(s), that takes a string s as input, and return the MINIMUM change required to make s a strong pas...
It is a unsupervised machine learning method to do the dimension reduction. It creates a minimum reduced dimension k which can make the new pairwise data distance preserved within an accepted error comparing to the original pairwise data distance. ...
Do not allocate extra space for another array, you must do this in place with constant memory. Input: [1,1,2] Output: 2 Assumptions: Do not allocate extra space for another array, you must do this in place with constant memory.