public int[] withoutTen(int[] nums) {
int[] result=null;
for(int i=0;i<nums.length;i++){
if(nums[i]!=10){
result=nums;
}
else if(nums[i]==10){
nums[i]=0;
}
}
return result;
}
Expected Run
withoutTen([1, 10, 10, 2]) → [1, 2, 0, 0] [1, 0, 0, 2] X
withoutTen([10, 2, 10]) → [2, 0, 0] [0, 2, 0] X
withoutTen([1, 99, 10]) → [1, 99, 0] [1, 99, 0] OK
withoutTen([10, 13, 10, 14]) → [13, 14, 0, 0] [0, 13, 0, 14] X
withoutTen([10, 13, 10, 14, 10]) → [13, 14, 0, 0, 0] [0, 13, 0, 14, 0] X
withoutTen([10, 10, 3]) → [3, 0, 0] [0, 0, 3] X
withoutTen([1]) → [1] [1] OK
withoutTen([13, 1]) → [13, 1] [13, 1] OK
withoutTen([10]) → [0] null X
withoutTen([]) → [] null X
other tests
X
public int[] withoutTen(int[] nums) {
int[] result=null;
for(int i=0;i<nums.length;i++){
if(nums[i]!=10){
result=nums;
}
else if(nums[i]==10){
nums[i]=0;
}
}
//return result;
int len=nums.length;
int[] arr=new int[len];
int front=0;
int back=len-1;
for(int i=0;i<nums.length;i++){
if(nums[i]%2==1){
arr[front]=nums[i];
front++;
}
else if(nums[i]%2==0){
arr[back]=nums[i];
back--;
}
}
return arr;
}
Expected Run
withoutTen([1, 10, 10, 2]) → [1, 2, 0, 0] [1, 2, 0, 0] OK
withoutTen([10, 2, 10]) → [2, 0, 0] [0, 2, 0] X
withoutTen([1, 99, 10]) → [1, 99, 0] [1, 99, 0] OK
withoutTen([10, 13, 10, 14]) → [13, 14, 0, 0] [13, 14, 0, 0] OK
withoutTen([10, 13, 10, 14, 10]) → [13, 14, 0, 0, 0] [13, 0, 14, 0, 0] X
withoutTen([10, 10, 3]) → [3, 0, 0] [3, 0, 0] OK
withoutTen([1]) → [1] [1] OK
withoutTen([13, 1]) → [13, 1] [13, 1] OK
withoutTen([10]) → [0] [0] OK
withoutTen([]) → [] [] OK
other tests
X
public int[] withoutTen(int[] nums) {
int len=nums.length;
int[] arr=new int[len];
int front=0;
int back=len-1;
for(int i=0;i<nums.length;i++){
if(nums[i]%10==1||nums[i]%10==2||nums[i]%10==3||nums[i]%10==4||nums[i]%10==5||nums[i]%10==6||nums[i]%10==7||nums[i]%10==8||nums[i]%10==9){
arr[front]=nums[i];
front++;
}
else {
arr[back]=nums[i];
back--;
}
if(arr[i]%10==0){
arr[i]=0;
}
}
return arr;
}
Expected Run
withoutTen([1, 10, 10, 2]) → [1, 2, 0, 0] [1, 2, 0, 0] OK
withoutTen([10, 2, 10]) → [2, 0, 0] [2, 10, 0] X
withoutTen([1, 99, 10]) → [1, 99, 0] [1, 99, 0] OK
withoutTen([10, 13, 10, 14]) → [13, 14, 0, 0] [13, 14, 0, 0] OK
withoutTen([10, 13, 10, 14, 10]) → [13, 14, 0, 0, 0] [13, 14, 10, 0, 0] X
withoutTen([10, 10, 3]) → [3, 0, 0] [3, 0, 0] OK
withoutTen([1]) → [1] [1] OK
withoutTen([13, 1]) → [13, 1] [13, 1] OK
withoutTen([10]) → [0] [0] OK
withoutTen([]) → [] [] OK
other tests
OK
public int[] withoutTen(int[] nums) {
int len=nums.length;
int[] arr=new int[len];
int front=0;
int back=len-1;
for(int i=0;i<nums.length;i++){
if(nums[i]%10==1||nums[i]%10==2||nums[i]%10==3||nums[i]%10==4||nums[i]%10==5||nums[i]%10==6||nums[i]%10==7||nums[i]%10==8||nums[i]%10==9){
arr[front]=nums[i];
front++;
}
/* else {
arr[back]=nums[i];
back--;
}
if(arr[i]%10==0){
arr[i]=0;
}*/
}
return arr;
}
Expected Run
withoutTen([1, 10, 10, 2]) → [1, 2, 0, 0] [1, 2, 0, 0] OK
withoutTen([10, 2, 10]) → [2, 0, 0] [2, 0, 0] OK
withoutTen([1, 99, 10]) → [1, 99, 0] [1, 99, 0] OK
withoutTen([10, 13, 10, 14]) → [13, 14, 0, 0] [13, 14, 0, 0] OK
withoutTen([10, 13, 10, 14, 10]) → [13, 14, 0, 0, 0] [13, 14, 0, 0, 0] OK
withoutTen([10, 10, 3]) → [3, 0, 0] [3, 0, 0] OK
withoutTen([1]) → [1] [1] OK
withoutTen([13, 1]) → [13, 1] [13, 1] OK
withoutTen([10]) → [0] [0] OK
withoutTen([]) → [] [] OK
other tests
OK
nums[i]%10 != 0
right?public int[] withoutTen(int[] nums) {
int len=nums.length;
int[] arr=new int[len];
int front=0;
int back=len-1;
for(int i=0;i<nums.length;i++){
if(nums[i]%10 != 0){
arr[front]=nums[i];
front++;
}
/* else {
arr[back]=nums[i];
back--;
}
if(arr[i]%10==0){
arr[i]=0;
}*/
}
return arr;
}
if (nums[i]%10 != 0) {
if (nums[i] != 10) {
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
11 Experts available now in Live!