initial
This commit is contained in:
commit
74ae93a96e
1 changed files with 94691 additions and 0 deletions
41
joplin notion extension/Web Development/DSA/Practice.md
Normal file
41
joplin notion extension/Web Development/DSA/Practice.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
Practice
|
||||
|
||||
```js
|
||||
function getDistinct(arr) {
|
||||
const disArr=[]
|
||||
for(let ele of arr){
|
||||
if(!disArr.includes(ele)){
|
||||
disArr.push(ele)
|
||||
}
|
||||
}
|
||||
|
||||
return disArr
|
||||
}
|
||||
|
||||
const arr=[4,6,8,4,8,14,16,14]
|
||||
// console.log(getDistinct(arr))
|
||||
|
||||
|
||||
function sumtotal2(arr,total,set) {
|
||||
if(total == 0){
|
||||
return set;
|
||||
}
|
||||
|
||||
for(let i=0;i < arr.length;i++){
|
||||
console.log('i: ',i)
|
||||
console.log('!set.includes(i ) ',!set.includes(i ))
|
||||
console.log('total: ',total)
|
||||
if(arr[i] <=total && !set.includes(i )){
|
||||
return sumtotal2(arr,total-arr[i], [...set,i])
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sumtotal(arr,total) {
|
||||
return sumtotal2(arr,total,[])
|
||||
}
|
||||
|
||||
const arr2 = [6,2,1,1,13,1,0,7,10,1,3]
|
||||
console.log(sumtotal(arr2,13))
|
||||
```
|
||||
Loading…
Reference in a new issue