/** Do not return anything, modify nums in-place instead. */ functionmoveZeroes(nums: number[]): void{ let leftIndex = 0; let rightIndex = nums.length - 1; while (leftIndex <= rightIndex) { if (nums[leftIndex] !== 0) { leftIndex++; continue; } nums.splice(leftIndex, 1); nums.push(0); rightIndex--; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
impl Solution { pubfnmove_zeroes(nums: &mutVec<i32>) { letmut left = 0; letmut right = nums.len(); while left < right { if nums[left] == 0 { nums.splice(left..left + 1, []); nums.push(0); right = right - 1; } else { left = left + 1; } } } }
functioncontainsDuplicate(nums: number[]): boolean{ let numSet = new Set(); for (let i = 0; i < nums.length; i++) { if (numSet.has(nums[i])) { returntrue; } numSet.add(nums[i]); } returnfalse; }
use ::std::io; fnmain() { letmut n = String::new(); io::stdin().read_line(&mut n).expect("输入错误"); let n: i64 = n.trim().parse().expect("不是数字"); letmut index = 0; letmut first = 0; letmut second = 1; while index <= n { if index == 0 || index == 1 { println!("count {}", index); } else { let count: i64 = first + second; first = second; second = count; println!("count {}", count); } index += 1; } }