这里介绍2中方式:js代码如下 var arr=[1,7,3,2,1,4,12,3,"3",3] function compare(arr) { var result = [], isfl; for (var i = 0; i < arr.length; i++) { isfl= false; for (var j = 0; j < result.length; j++) { if (arr[i] ===result[j]) { isfl = true; break; }…
Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 如题目所诉,去除递增链表中重复值的节点. 刚开始思路如下: 设置一个指针用于遍历全部节点 让每个节点和其next节点值比较…
//完美去除法: var arr=[1,3,2,2,11,4]; var arr1=[]; var arr2=arr.sort(function(a,b){ return a-b; }); //把数组进行排序 var num=1; for (var i=0;i<arr2.length;i++){ if(arr2[i]!==arr2[(num++)]){ arr1.push(arr[i]); } } console.log(arr1);…