https://leetcode-cn.com/problems/implement-queue-using-stacks/

    1. class MyQueue {
    2. private inStack: number[];
    3. private outStack: number[];
    4. constructor() {
    5. this.inStack = [];
    6. this.outStack = [];
    7. }
    8. push(x: number): void {
    9. this.inStack.push(x);
    10. }
    11. pop(): number {
    12. if (this.outStack.length === 0) {
    13. while (this.inStack.length) {
    14. this.outStack.push(this.inStack.pop());
    15. }
    16. }
    17. if (this.outStack.length === 0) {
    18. return null;
    19. }
    20. return this.outStack.pop();
    21. }
    22. peek(): number {
    23. if (this.outStack.length === 0) {
    24. while (this.inStack.length) {
    25. this.outStack.push(this.inStack.pop());
    26. }
    27. }
    28. if (this.outStack.length === 0) {
    29. return null;
    30. }
    31. return this.outStack[this.outStack.length - 1];
    32. }
    33. empty(): boolean {
    34. return !this.inStack.length && !this.outStack.length;
    35. }
    36. }

    https://bigfrontend.dev/zh/problem/the-angle-between-hour-hand-and-minute-hand-of-a-clock

    
    /**
     * @param {string} time
     * @returns {number} 
     */
    function angle(time) {
      let [hours, minutes] = time.split(':').map(Number);
      // 12小时制
      hours = hours % 12;
      // 每分钟6度,一圈为60分钟
      const mDPM = 360 / 60;
      // 每小时30度,一圈12小时(整点的情况下)
      const hDPM = 360 / 12;
      // 超出部分,比如01:30,时针度数在1和2正中间。
      // 一分钟,时针偏移0.5度,30分钟时针偏移15度
      const extra = 360 / 12 / 60 * minutes;
      // 时针度数
      const hoursAngle = hDPM * hours + extra;
      // 分针度数
      const minutesAngle = mDPM * minutes;
      // 计算角度
      const diff = Math.abs(hoursAngle - minutesAngle);
      // 四舍五入,是否超过180
      return Math.round(Math.min(diff, 360 - diff));
    }