当前位置:网站首页>Force deduction exercise -- deleting repeated items in ordered sequence 1.0
Force deduction exercise -- deleting repeated items in ordered sequence 1.0
2022-06-30 05:36:00 【Life is too hard】
Ideas for solving this problem : Yes, it is result This variable is used to record several different elements
Then loop through the array , Whether the elements of the current index and the next index are consistent , To determine how many different elements there are
however ,result It also indicates the actual position of this different element in the array . This is my personal language explanation ,
The explanation may not be very clear , You can understand it by looking at the code , Welcome comments if you don't understand . You are also welcome to give us some advice .
class Solution {
public int removeDuplicates(int[] nums) {
// Judge whether it is empty first , If it is blank, it can be directly output as 0
if (nums.length == 0) return 0;
// Define a variable to record a total of several distinct data
int result = 1;
// If the array length is 1 It can also be output directly
if (nums.length == 1) return result;
// Traverse... With a loop nums Array
for (int i = 0; i < nums.length-1; i++) {
/* Judge here Current nums Of the i Array elements And the next array Whether the elements are consistent , That is the first. i+1 Elements , If consistent, enter if Statement Libiao */
if (nums[i] != nums[i+1]) {
/* here result It records that there are several different data in the array , At the same time, it can also indicate where the next element and the previous element should be located At this time, you only need to assign the next data in the array to nums Array of result Location is OK */
nums[result] = nums[i+1];
result++;
}
}
return result;
}
}
边栏推荐
- 抓取手机端变体组合思路设想
- 旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)
- D. Big Brush
- Sword finger offer 22 The penultimate node in the linked list
- The fourth day of learning C language for Asian people
- Unity call Exe program
- Promise知识点拾遗
- Xi'an Jiaotong 21st autumn online expansion resources of online trade and marketing (III) [standard answer]
- Unity3d position the model, rotate, drag and zoom around the model to obtain the center point of the model
- Fifty years ago, the go code first submitted by the inventor of Hello world was as long as this
猜你喜欢

We strongly recommend more than a dozen necessary plug-ins for idea development

token 过期后,如何自动续期?

Unit asynchronous jump progress

Baiwen.com 7 days Internet of things smart home learning experience punch in the third day

Introduction to mmcv common APIs

Unity scroll view element drag and drop to automatically adsorb centering and card effect

Unity ugui text value suspended enlarged display add text background

VFPBS在IIS下调用EXCEL遇到的Access is denied

OpenCL线程代数库ViennaCL的使用

【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
随机推荐
如何写论文
Array pointers and pointer arrays
C # uses monopinvokecallback to directly call back C # function
Codeforces Round #390 (Div. 2) D. Fedor and coupons
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
Solitidy - fallback 回退函数 - 2种触发执行方式
Golden code of programmer interview
[notes] unity webgl input Chinese
How to create a CSR (certificate signing request) file?
Pyinstaller flash back
[Blue Bridge Road -- bug free code] analysis of AT24C02 storage code
9. naive Bayes
C. Divan and bitwise operations
Unity 3D model operation and UI conflict Scrollview
Xi'an Jiaotong automation control theory test simulation question [standard answer]
Unity publishing /build settings
VFPBS在IIS下调用EXCEL遇到的Access is denied
Rotating frame target detection mmrotate v0.3.1 learning configuration
PyGame. Why can't I exit when I click X in the window? I can only exit when I return idle
Bev instance prediction based on monocular camera (iccv 2021)