当前位置:网站首页>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;
}
}
边栏推荐
- 【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
- Bev instance prediction based on monocular camera (iccv 2021)
- SSL证书续费相关问题详解
- English语法_形容词/副词3级-最高级
- Did you know that WPS can turn on eye protection mode?
- How to judge the quality of network transformer? What symptom is network filter transformer broken?
- Unity shortcut key
- Stack overflow caused by C # using protobuf stack overflow
- Unity ugui text value suspended enlarged display add text background
- Baiwen.com 7 days Internet of things smart home learning experience punch in the third day
猜你喜欢

Sound network, standing in the "soil" of the Internet of things

Responding with flow layout

图扑软件基于钻孔数据的三维地质模型可视化

English语法_形容词/副词3级-最高级

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

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

Delete the repeating elements in the sorting list (simple questions)

终端便捷ssh(免密)连接

Unity ugui text value suspended enlarged display add text background

抓取手机端变体组合思路设想
随机推荐
Super comprehensive summary | related improvement codes of orb-slam2 / orb-slam3!
How to create a CSR (certificate signing request) file?
Idea of capturing mobile terminal variant combination
Unity publishing /build settings
Rotating frame target detection mmrotate v0.3.1 learning configuration
Sound network, standing in the "soil" of the Internet of things
Rotation, translation and scaling of unity VR objects
Is it safe to open an account and trade with a compass?
2022年,谁在推动音视频产业的新拐点?
Access is denied encountered when vfpbs calls excel under IIS
Sword finger offer 18 Delete the node of the linked list
Did you know that WPS can turn on eye protection mode?
Question mark (?) in Cron expression Use of
[typescript] cannot redeclare block range variables
Qt之QListView的简单使用(含源码+注释)
Stack overflow caused by C # using protobuf stack overflow
How to write a thesis
图扑软件基于钻孔数据的三维地质模型可视化
E: Topic focus
Unity 3D model operation and UI conflict Scrollview