xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

LeetCode study plans All In One

LeetCode study plans All In One

https://leetcode.com/studyplan/

demos

Google

// Hard ❓

https://leetcode.com/problems/guess-the-word/?envType=study-plan-v2&envId=google-spring-23-high-frequency

Amazon

// Medium ✅
function kthFactor(n: number, k: number): number {
  const list = [];
  for (let i = 0; i <= n; i++) {
    if(n % i === 0) {
      // console.log(`i =`, i);
      list.push(i);
    }
  }
  // console.log(`list =`, list);
  if(!list[k - 1]) {
    return -1;
  }
  return list[k - 1];
};

https://leetcode.com/problems/the-kth-factor-of-n/?envType=study-plan-v2&envId=amazon-spring-23-high-frequency

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

LeetCode 75

Ace Coding Interview with 75 questions

https://leetcode.com/studyplan/leetcode-75/

image

// Easy ✅
function mergeAlternately(word1: string, word2: string): string {
  let result = ``;
  const words1 = word1.split(``);
  const words2 = word2.split(``);
  if(words1.length >= words2.length) {
    for(let i = 0; i < words1.length; i++) {
      result += words1[i];
      if(words2[i]) {
        result += words2[i];
      }
    }
  } else {
    for(let i = 0; i < words2.length; i++) {
      if(words1[i]) {
        result += words1[i];
      }
      result += words2[i];
    }
  }
  return result;
};

https://leetcode.com/problems/merge-strings-alternately/description/?envType=study-plan-v2&envId=leetcode-75

Top Interview 150

Must-do List for Interview Prepare

https://leetcode.com/studyplan/top-interview-150/

// Easy ✅
/**
 * @param {number[]} nums1
 * @param {number} m
 * @param {number[]} nums2
 * @param {number} n
 * @return {void} Do not return anything, modify nums1 in-place instead.
 */
var merge = function(nums1, m, nums2, n) {
  for (let i = 0; i < n; i++) {
    nums1[m + i] = nums2[i];
  }
  // nums1 = nums1.sort();
  nums1 = nums1.sort((a, b) => a > b ? 1 : -1);
};


/*

[-1,-1,-1,-1,-1,-10,-10,-10,-10].sort();
// (9) [-1, -1, -1, -1, -1, -10, -10, -10, -10]

[-1,-1,-1,-1,-1,-10,-10,-10,-10].sort((a, b) => a > b ? 1 : -1);
// (9) [-10, -10, -10, -10, -1, -1, -1, -1, -1]

*/

/*

var merge = function(nums1, m, nums2, n) {
  for (let i = 0; i < n; i++) {
    nums1[m + i] = nums2[i];
  }
  for (let i = 0; i < nums1.length; i++) {
    if(nums1[i] > nums1[i + 1]) {
      [
        nums1[i],
        nums1[i + 1]
      ] = [
        nums1[i + 1],
        nums1[i],
      ]
    }
  }
};


*/


/*


var merge = function(nums1, m, nums2, n) {
  // Do not return anything, modify nums1 in-place instead.
  // return nums1.slice(0, m).concat(nums2.slice(0, n)).sort((a, b) => a -b > 0 ? 1 : -1);
  // nums1.slice(0, m).concat(nums2.slice(0, n));
  if(m < 1) {
    nums1[m] = nums2[0];
  } else {
    for(let i = 0; i < n; i++) {
      let temp = nums2[i];
      if(temp > nums1[m + i - 1]) {
        nums1[m + i] = temp;
      } else {
        // ES6 swap
        // [
        //   [m + i],
        //   nums1[m - 1 + i],
        // ] = [
        //   nums1[m - 1 + i],
        //   [m + i],
        // ]
        let big = nums1[m - 1 + i];
        nums1[m - 1 + i] = temp;
        nums1[m + i] = big;
      }
    }
  }
};

*/

https://leetcode.com/problems/merge-sorted-array/description/?envType=study-plan-v2&envId=top-interview-150

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2024-05-21 15:22  xgqfrms  阅读(5)  评论(0编辑  收藏  举报