In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the realization method of C# mobile zero-sum staircase climbing". The content of the article is simple and clear, and it is easy to learn and understand. let's study and learn "what is the realization method of C# mobile zero-sum staircase climbing"?
Given an array nums, write a function to move all zeros to the end of the array while maintaining the relative order of non-zero elements.
Example:
Input: [0meme1pence0pence3pr 12]
Output: [1, 3, 12, 0, 0]
Description:
Must operate on the original array, and additional arrays cannot be copied.
Minimize the number of operations.
Public void MoveZeroes (int [] nums)
{
/ / solution 1: deal with those that are not 0, and then process those that are 0
If (nums = = null | | nums.Length = = 0)
Return
Int index = 0
For (int I = 0; I
< nums.Length; i++) { if (nums[i] != 0) nums[index++] = nums[i]; } while (index < nums.Length) { nums[index++] = 0; } // 解法2:遇到不为0的 互换位置 int j = 0; for (int i = 0; i < nums.Length; i++) { if (nums[i] != 0) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; j++; } } }The official website of the topic links to https://leetcode-cn.com/problems/climbing-stairs/
seventy。 Climb the stairs
Suppose you are climbing the stairs. You need step n to get to the roof.
You can climb one or two steps at a time. How many different ways do you have to climb to the roof?
Note: given n is a positive integer.
Example 1:
Enter: 2
Output: 2
Explanation: there are two ways to climb to the roof.
1. Order 1 + 1
2. Order 2
Example 2:
Enter: 3
Output: 3
Explanation: there are three ways to climb to the roof.
1. 1 order + 1 order + 1 order
2. Order 1 + 2
3. Order 2 + 1
Public int ClimbStairs (int n)
{
/ / solution 1: recursion (memory search)
/ / int [] memo = new int [n + 1]
/ / return helper (n, memo)
/ solution 2: dynamic programming
/ / if (n = = 1)
/ / return 1
/ / int [] dp = new int [n + 1]
/ / dp [1] = 1
/ / dp [2] = 2
/ / for (int I = 3; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 288
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.