---
# System prepended metadata

title: 'Week 4: May 22nd - May 28th'
tags: [pixnet, leetcode]

---

# Week 4: May 22nd - May 28th

## N-Queens

### ==Solution:==


---


## Find the Shortest Superstring

### ==Solution:==


## To Lower Case

### Solution:
- Shan
```typescript
function toLowerCase(s: string): string {
    let result=[];
    s.split('').forEach(item=> {
        let utf = item.charCodeAt(0);
        if( utf < 91 && utf > 64){
            utf+=32;
            result.push(String.fromCharCode(utf));
        }else{
            result.push(item); 
        } 
    });
  return result.join('');
};
```

---
## Maximum Gap

### ==Solution:==

- Shan
```javascript
var maximumGap = function(nums) {

  let diffArr = [];
  nums.sort(function(a, b) {
    return a - b;
  });

  nums.reduce((acc, cur) => {
    diffArr.push(Math.abs(cur - acc));
    return cur;
  });

  return diffArr.length === 0 ? 0 : Math.max(...diffArr);

};
```


---

## Search Suggestions System
### ==Solution:== 
- Shan
```javascript
var suggestedProducts = function(products, searchWord) {
    
    let result = [];
    products.sort();


    for (let i = 1; i <= searchWord.length; i++) {
      let re = strReg(searchWord.slice(0, i));
      result.push(productFilter(products, re));
    }

    function strReg(str) {
      return new RegExp(`^${str}`);
    }
    
    function productFilter(productList, re) {
      return productList.filter(item => re.test(item)).splice(0,3);

    }
    return result;
    
};
```
:::warning
效能很差，超過 1000 ms
照官方建議應該使用的概念
Binary Search + Trie + DFS
:::



###### tags: `leetcode` `pixnet`