Compare commits
2 Commits
92ee8e1383
...
3650ccd44b
| Author | SHA1 | Date | |
|---|---|---|---|
| 3650ccd44b | |||
| 4cd15619f9 |
4
src/cn/celess/common/ListNode.java
Normal file
4
src/cn/celess/common/ListNode.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package cn.celess.common;
|
||||
|
||||
public class ListNode {
|
||||
}
|
||||
36
src/cn/celess/leetcode/test125/Solution.java
Normal file
36
src/cn/celess/leetcode/test125/Solution.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package cn.celess.leetcode.test125;
|
||||
|
||||
class Solution {
|
||||
public boolean isPalindrome(String s) {
|
||||
int left =0;
|
||||
int right = s.length()-1;
|
||||
|
||||
|
||||
while(left <= right){
|
||||
char leftChar = Character.toLowerCase(s.charAt(left));
|
||||
char rightChar = Character.toLowerCase(s.charAt(right));
|
||||
if(!((int)leftChar>=(int)'0' && (int)leftChar<=(int)'9') && !((int)leftChar>=(int)'a' && (int)leftChar<=(int)'z')){
|
||||
left++;
|
||||
continue;
|
||||
}
|
||||
if(!((int)rightChar>=(int)'0' && (int)rightChar<=(int)'9') && !((int)rightChar>=(int)'a' && (int)rightChar<=(int)'z')){
|
||||
right--;
|
||||
continue;
|
||||
}
|
||||
if (leftChar != rightChar){
|
||||
return false;
|
||||
}
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Solution().isPalindrome("race a car"));
|
||||
System.out.println(new Solution().isPalindrome("A man, a plan, a canal: Panama"));
|
||||
}
|
||||
}
|
||||
15
src/cn/celess/leetcode/test147/Solution.java
Normal file
15
src/cn/celess/leetcode/test147/Solution.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package cn.celess.leetcode.test147;
|
||||
|
||||
import cn.celess.common.ListNode;
|
||||
|
||||
class Solution {
|
||||
public boolean hasCycle(ListNode head) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.leetcode.topinterview150.test26;
|
||||
package cn.celess.leetcode.test26;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.leetcode.topinterview150.test26;
|
||||
package cn.celess.leetcode.test26;
|
||||
|
||||
class Solution {
|
||||
public int removeDuplicates(int[] nums) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.leetcode.topinterview150.test27;
|
||||
package cn.celess.leetcode.test27;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.leetcode.topinterview150.test27;
|
||||
package cn.celess.leetcode.test27;
|
||||
|
||||
class Solution {
|
||||
public int removeElement(int[] nums, int val) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.leetcode.topinterview150.test80;
|
||||
package cn.celess.leetcode.test80;
|
||||
|
||||
public class Solution {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。
|
||||
//
|
||||
// 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。
|
||||
//
|
||||
// 返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0 。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例 1:
|
||||
//
|
||||
//
|
||||
//输入:[7,1,5,3,6,4]
|
||||
//输出:5
|
||||
//解释:在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
|
||||
// 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。
|
||||
//
|
||||
//
|
||||
// 示例 2:
|
||||
//
|
||||
//
|
||||
//输入:prices = [7,6,4,3,1]
|
||||
//输出:0
|
||||
//解释:在这种情况下, 没有交易完成, 所以最大利润为 0。
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// 提示:
|
||||
//
|
||||
//
|
||||
// 1 <= prices.length <= 10⁵
|
||||
// 0 <= prices[i] <= 10⁴
|
||||
//
|
||||
//
|
||||
// Related Topics 数组 动态规划 👍 3876 👎 0
|
||||
|
||||
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public int maxProfit(int[] prices) {
|
||||
int minPrice = Integer.MAX_VALUE;
|
||||
int maxProfit = 0;
|
||||
for (int price : prices) {
|
||||
minPrice = Math.min(minPrice, price);
|
||||
maxProfit = Math.max(maxProfit, price - minPrice);
|
||||
}
|
||||
return maxProfit;
|
||||
}
|
||||
}
|
||||
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
void main() {
|
||||
System.out.println(new Solution().maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
|
||||
System.out.println(new Solution().maxProfit(new int[]{7,6,4,3,1}));
|
||||
System.out.println(new Solution().maxProfit(new int[]{3,2,6,5,0,3}));
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//给你一个整数数组 prices ,其中 prices[i] 表示某支股票第 i 天的价格。
|
||||
//
|
||||
// 在每一天,你可以决定是否购买和/或出售股票。你在任何时候 最多 只能持有 一股 股票。你也可以先购买,然后在 同一天 出售。
|
||||
//
|
||||
// 返回 你能获得的 最大 利润 。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例 1:
|
||||
//
|
||||
//
|
||||
//输入:prices = [7,1,5,3,6,4]
|
||||
//输出:7
|
||||
//解释:在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4。
|
||||
//随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6 - 3 = 3。
|
||||
//最大总利润为 4 + 3 = 7 。
|
||||
//
|
||||
// 示例 2:
|
||||
//
|
||||
//
|
||||
//输入:prices = [1,2,3,4,5]
|
||||
//输出:4
|
||||
//解释:在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4。
|
||||
//最大总利润为 4 。
|
||||
//
|
||||
// 示例 3:
|
||||
//
|
||||
//
|
||||
//输入:prices = [7,6,4,3,1]
|
||||
//输出:0
|
||||
//解释:在这种情况下, 交易无法获得正利润,所以不参与交易可以获得最大利润,最大利润为 0。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 提示:
|
||||
//
|
||||
//
|
||||
// 1 <= prices.length <= 3 * 10⁴
|
||||
// 0 <= prices[i] <= 10⁴
|
||||
//
|
||||
//
|
||||
// Related Topics 贪心 数组 动态规划 👍 2774 👎 0
|
||||
|
||||
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public int maxProfit(int[] prices) {
|
||||
|
||||
}
|
||||
}
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
49
src/leetcode/editor/cn/SolutionMajorityElement.java
Normal file
49
src/leetcode/editor/cn/SolutionMajorityElement.java
Normal file
@@ -0,0 +1,49 @@
|
||||
//给定一个大小为 n 的数组 nums ,返回其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。
|
||||
//
|
||||
// 你可以假设数组是非空的,并且给定的数组总是存在多数元素。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例 1:
|
||||
//
|
||||
//
|
||||
//输入:nums = [3,2,3]
|
||||
//输出:3
|
||||
//
|
||||
// 示例 2:
|
||||
//
|
||||
//
|
||||
//输入:nums = [2,2,1,1,1,2,2]
|
||||
//输出:2
|
||||
//
|
||||
//
|
||||
//
|
||||
//提示:
|
||||
//
|
||||
//
|
||||
// n == nums.length
|
||||
// 1 <= n <= 5 * 10⁴
|
||||
// -10⁹ <= nums[i] <= 10⁹
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// 进阶:尝试设计时间复杂度为 O(n)、空间复杂度为 O(1) 的算法解决此问题。
|
||||
//
|
||||
// Related Topics 数组 哈希表 分治 计数 排序 👍 2542 👎 0
|
||||
|
||||
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public int majorityElement(int[] nums) {
|
||||
Arrays.sort(nums);
|
||||
return nums[nums.length/2];
|
||||
}
|
||||
}
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
|
||||
|
||||
public void main(String[] args) {
|
||||
System.out.println(new Solution().majorityElement(new int[]{3,2,3}));
|
||||
System.out.println(new Solution().majorityElement(new int[]{2,2,1,1,1,2,2}));
|
||||
}
|
||||
73
src/leetcode/editor/cn/SolutionRotateArray.java
Normal file
73
src/leetcode/editor/cn/SolutionRotateArray.java
Normal file
@@ -0,0 +1,73 @@
|
||||
//给定一个整数数组 nums,将数组中的元素向右轮转 k 个位置,其中 k 是非负数。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例 1:
|
||||
//
|
||||
//
|
||||
//输入: nums = [1,2,3,4,5,6,7], k = 3
|
||||
//输出: [5,6,7,1,2,3,4]
|
||||
//解释:
|
||||
//向右轮转 1 步: [7,1,2,3,4,5,6]
|
||||
//向右轮转 2 步: [6,7,1,2,3,4,5]
|
||||
//向右轮转 3 步: [5,6,7,1,2,3,4]
|
||||
//
|
||||
//
|
||||
// 示例 2:
|
||||
//
|
||||
//
|
||||
//输入:nums = [-1,-100,3,99], k = 2
|
||||
//输出:[3,99,-1,-100]
|
||||
//解释:
|
||||
//向右轮转 1 步: [99,-1,-100,3]
|
||||
//向右轮转 2 步: [3,99,-1,-100]
|
||||
//
|
||||
//
|
||||
//
|
||||
// 提示:
|
||||
//
|
||||
//
|
||||
// 1 <= nums.length <= 10⁵
|
||||
// -2³¹ <= nums[i] <= 2³¹ - 1
|
||||
// 0 <= k <= 10⁵
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// 进阶:
|
||||
//
|
||||
//
|
||||
// 尽可能想出更多的解决方案,至少有 三种 不同的方法可以解决这个问题。
|
||||
// 你可以使用空间复杂度为 O(1) 的 原地 算法解决这个问题吗?
|
||||
//
|
||||
//
|
||||
// Related Topics 数组 数学 双指针 👍 2425 👎 0
|
||||
|
||||
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public void rotate(int[] nums, int k) {
|
||||
k = k % nums.length;
|
||||
int[] arr = new int[k];
|
||||
System.arraycopy(nums, nums.length - k, arr, 0, k);
|
||||
|
||||
// int right = nums.length - 1;
|
||||
// while (right >= k) {
|
||||
// nums[right] = nums[right - k];
|
||||
// right--;
|
||||
// }
|
||||
System.arraycopy(nums, 0, nums, k, nums.length - k);
|
||||
System.arraycopy(arr, 0, nums, 0, k);
|
||||
}
|
||||
}
|
||||
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
void main() {
|
||||
// System.out.println(-3 % 1);
|
||||
|
||||
// [1,2] -> [2,1] -> [1,2]
|
||||
|
||||
int[] arr = new int[]{1,2,3,4,5,6,7};
|
||||
new Solution().rotate(arr, 3);
|
||||
System.out.println(Arrays.toString(arr));
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<p>给定一个数组 <code>prices</code> ,它的第 <code>i</code> 个元素 <code>prices[i]</code> 表示一支给定股票第 <code>i</code> 天的价格。</p>
|
||||
|
||||
<p>你只能选择 <strong>某一天</strong> 买入这只股票,并选择在 <strong>未来的某一个不同的日子</strong> 卖出该股票。设计一个算法来计算你所能获取的最大利润。</p>
|
||||
|
||||
<p>返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 <code>0</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>[7,1,5,3,6,4]
|
||||
<strong>输出:</strong>5
|
||||
<strong>解释:</strong>在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
|
||||
注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>prices = [7,6,4,3,1]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>在这种情况下, 没有交易完成, 所以最大利润为 0。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= prices.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= prices[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<div><div>Related Topics</div><div><li>数组</li><li>动态规划</li></div></div><br><div><li>👍 3876</li><li>👎 0</li></div>
|
||||
@@ -0,0 +1,42 @@
|
||||
<p>给你一个整数数组 <code>prices</code> ,其中 <code>prices[i]</code> 表示某支股票第 <code>i</code> 天的价格。</p>
|
||||
|
||||
<p>在每一天,你可以决定是否购买和/或出售股票。你在任何时候 <strong>最多</strong> 只能持有 <strong>一股</strong> 股票。你也可以先购买,然后在 <strong>同一天</strong> 出售。</p>
|
||||
|
||||
<p>返回 <em>你能获得的 <strong>最大</strong> 利润</em> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>prices = [7,1,5,3,6,4]
|
||||
<strong>输出:</strong>7
|
||||
<strong>解释:</strong>在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4。
|
||||
随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6 - 3 = 3。
|
||||
最大总利润为 4 + 3 = 7 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>prices = [1,2,3,4,5]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4。
|
||||
最大总利润为 4 。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>prices = [7,6,4,3,1]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>在这种情况下, 交易无法获得正利润,所以不参与交易可以获得最大利润,最大利润为 0。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= prices.length <= 3 * 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= prices[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<div><div>Related Topics</div><div><li>贪心</li><li>数组</li><li>动态规划</li></div></div><br><div><li>👍 2774</li><li>👎 0</li></div>
|
||||
@@ -0,0 +1,33 @@
|
||||
<p>给定一个大小为 <code>n</code><em> </em>的数组 <code>nums</code> ,返回其中的多数元素。多数元素是指在数组中出现次数 <strong>大于</strong> <code>⌊ n/2 ⌋</code> 的元素。</p>
|
||||
|
||||
<p>你可以假设数组是非空的,并且给定的数组总是存在多数元素。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [3,2,3]
|
||||
<strong>输出:</strong>3</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [2,2,1,1,1,2,2]
|
||||
<strong>输出:</strong>2
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<strong>提示:</strong>
|
||||
|
||||
<ul>
|
||||
<li><code>n == nums.length</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>进阶:</strong>尝试设计时间复杂度为 O(n)、空间复杂度为 O(1) 的算法解决此问题。</p>
|
||||
|
||||
<div><div>Related Topics</div><div><li>数组</li><li>哈希表</li><li>分治</li><li>计数</li><li>排序</li></div></div><br><div><li>👍 2542</li><li>👎 0</li></div>
|
||||
73
src/leetcode/editor/cn/doc/content/SolutionRomanToInteger.md
Normal file
73
src/leetcode/editor/cn/doc/content/SolutionRomanToInteger.md
Normal file
@@ -0,0 +1,73 @@
|
||||
<p>罗马数字包含以下七种字符: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>,<code>C</code>,<code>D</code> 和 <code>M</code>。</p>
|
||||
|
||||
<pre>
|
||||
<strong>字符</strong> <strong>数值</strong>
|
||||
I 1
|
||||
V 5
|
||||
X 10
|
||||
L 50
|
||||
C 100
|
||||
D 500
|
||||
M 1000</pre>
|
||||
|
||||
<p>例如, 罗马数字 <code>2</code> 写做 <code>II</code> ,即为两个并列的 1 。<code>12</code> 写做 <code>XII</code> ,即为 <code>X</code> + <code>II</code> 。 <code>27</code> 写做 <code>XXVII</code>, 即为 <code>XX</code> + <code>V</code> + <code>II</code> 。</p>
|
||||
|
||||
<p>通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做 <code>IIII</code>,而是 <code>IV</code>。数字 1 在数字 5 的左边,所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地,数字 9 表示为 <code>IX</code>。这个特殊的规则只适用于以下六种情况:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>I</code> 可以放在 <code>V</code> (5) 和 <code>X</code> (10) 的左边,来表示 4 和 9。</li>
|
||||
<li><code>X</code> 可以放在 <code>L</code> (50) 和 <code>C</code> (100) 的左边,来表示 40 和 90。 </li>
|
||||
<li><code>C</code> 可以放在 <code>D</code> (500) 和 <code>M</code> (1000) 的左边,来表示 400 和 900。</li>
|
||||
</ul>
|
||||
|
||||
<p>给定一个罗马数字,将其转换成整数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> s = "III"
|
||||
<strong>输出:</strong> 3</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> s = "IV"
|
||||
<strong>输出:</strong> 4</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> s = "IX"
|
||||
<strong>输出:</strong> 9</pre>
|
||||
|
||||
<p><strong>示例 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> s = "LVIII"
|
||||
<strong>输出:</strong> 58
|
||||
<strong>解释:</strong> L = 50, V= 5, III = 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 5:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> s = "MCMXCIV"
|
||||
<strong>输出:</strong> 1994
|
||||
<strong>解释:</strong> M = 1000, CM = 900, XC = 90, IV = 4.</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 15</code></li>
|
||||
<li><code>s</code> 仅含字符 <code>('I', 'V', 'X', 'L', 'C', 'D', 'M')</code></li>
|
||||
<li>题目数据保证 <code>s</code> 是一个有效的罗马数字,且表示整数在范围 <code>[1, 3999]</code> 内</li>
|
||||
<li>题目所给测试用例皆符合罗马数字书写规则,不会出现跨位等情况。</li>
|
||||
<li>IL 和 IM 这样的例子并不符合题目要求,49 应该写作 XLIX,999 应该写作 CMXCIX 。</li>
|
||||
<li>关于罗马数字的详尽书写规则,可以参考 <a href="https://baike.baidu.com/item/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97/772296">罗马数字 - 百度百科</a>。</li>
|
||||
</ul>
|
||||
|
||||
<div><div>Related Topics</div><div><li>哈希表</li><li>数学</li><li>字符串</li></div></div><br><div><li>👍 2988</li><li>👎 0</li></div>
|
||||
44
src/leetcode/editor/cn/doc/content/SolutionRotateArray.md
Normal file
44
src/leetcode/editor/cn/doc/content/SolutionRotateArray.md
Normal file
@@ -0,0 +1,44 @@
|
||||
<p>给定一个整数数组 <code>nums</code>,将数组中的元素向右轮转 <code>k</code><em> </em>个位置,其中 <code>k</code><em> </em>是非负数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> nums = [1,2,3,4,5,6,7], k = 3
|
||||
<strong>输出:</strong> <span><code>[5,6,7,1,2,3,4]</code></span>
|
||||
<strong>解释:</strong>
|
||||
向右轮转 1 步: <span><code>[7,1,2,3,4,5,6]</code></span>
|
||||
向右轮转 2 步: <span><code>[6,7,1,2,3,4,5]
|
||||
</code></span>向右轮转 3 步: <span><code>[5,6,7,1,2,3,4]</code></span>
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [-1,-100,3,99], k = 2
|
||||
<strong>输出:</strong>[3,99,-1,-100]
|
||||
<strong>解释:</strong>
|
||||
向右轮转 1 步: [99,-1,-100,3]
|
||||
向右轮转 2 步: [3,99,-1,-100]</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
|
||||
<li><code>0 <= k <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>进阶:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>尽可能想出更多的解决方案,至少有 <strong>三种</strong> 不同的方法可以解决这个问题。</li>
|
||||
<li>你可以使用空间复杂度为 <code>O(1)</code> 的 <strong>原地 </strong>算法解决这个问题吗?</li>
|
||||
</ul>
|
||||
|
||||
<div><div>Related Topics</div><div><li>数组</li><li>数学</li><li>双指针</li></div></div><br><div><li>👍 2425</li><li>👎 0</li></div>
|
||||
Reference in New Issue
Block a user