小算法酱油笔记之数组压缩0

来源:互联网 发布:淘宝后台手机端 编辑:程序博客网 时间:2024/05/17 17:55
//将数组n中的0除去,并返回压缩后的数组public int[] ys(int[] n){int count=0;for(int t:n){if(t!=0)count++;}int[] c = new int[count];count=0;for(int t:n){if(t!=0)c[count++]=t;}return c;}