Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>letscode</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
24 changes: 24 additions & 0 deletions src/main/java/MoveZeroes/kunlingou/MoveZeroes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package MoveZeroes.kunlingou;

/**
* Created by kunlingou on 2019/5/29.
* 解题思路
* 通过copy对象对数组进行处理
* 1.去除0项
* 2.补全0
*/
public class MoveZeroes {
public void moveZeroes(int[] nums) {
int[] copy = nums.clone();
int j=0;
for(int i=0;i<copy.length;i++) {
if(copy[i] != 0) {
nums[j] = copy[i];
j++;
}
}
for(int i=j;i<copy.length;i++) {
nums[i] = 0;
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/RemoveElement/kunlingou/RemoveElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package RemoveElement.kunlingou;

/**
* Created by kunlingou on 2019/5/30.
* 解题思路
* 通过cursor游标思想对数组进行处理
*/
public class RemoveElement {
public int removeElement(int[] nums, int val) {
if(nums.length==0) return 0;
int cur = 0;
for(int i=0;i<nums.length;i++){
if(nums[i]!=val){
nums[cur] = nums[i];
cur++;
}
}
return cur;
}
}