The Travels of Marco Cai

  • Home

  • About

  • Tags

  • Archives

  • Search

[LeetCode] Challenge log 669

Posted on 2018-04-26 | Edited on 2018-04-27 |
669. Trim a Binary Search Tree

Recursive solution: Use the special property of binary search tree: left sons are smaller while right sons are greater.

Read more »

[LeetCode] Challenge log 575

Posted on 2018-04-26 | Edited on 2018-04-27 |
575. Distribute Candies

Super Straightforward.

if candies kinds > half of total, output the latter; otherwise the former.

Read more »

[LeetCode] Challenge log 682

Posted on 2018-04-26 | Edited on 2018-04-27 |
682. Baseball Game

Straightforward O(n).

Use two run and O(1) space.

Can use a stack to reduce to one run — O(n) space.

Read more »

[LeetCode] Challenge log 412

Posted on 2018-04-26 | Edited on 2018-04-27 |
412. Fizz Buzz

It isn’t really interesting.

Read more »

[SQL] [LeetCode] Challenge log 620

Posted on 2018-04-25 |
620. Department Top Three Salaries

Use SQL wildcard with like . % is any length. _ is one character.

Read more »

[LeetCode] Challenge log 500

Posted on 2018-04-25 |
500. Keyboard Row

Use dict to map charaters to row numbers.

Read more »

[LeetCode] Challenge log 557

Posted on 2018-04-25 |
557. Reverse Words in a String III

Self explained.

Read more »

[LeetCode] Challenge log 476

Posted on 2018-04-20 |
476. Number Complement
  1. Use XOR 11111… to flip bit.
  2. Use Mask to decide which bits are 1s.
Read more »

[LeetCode] Challenge log 806

Posted on 2018-04-19 |
806. Number of Lines To Write String

Straightforward.

Python string <-> ascii: ord() chr()

Read more »

[SQL] [LeetCode] Challenge log 627

Posted on 2018-04-19 |
627. Swap Salary

Sql if and case statement:

update [table] set [column] = if ([condition], [v1], [v2] )

(see case example at the end)

Read more »
1…789…13
Mingxiang Cai

Mingxiang Cai

A learner, a hobbyist.

128 posts
56 tags
© 2019 Mingxiang Cai
0%