-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.json
1 lines (1 loc) · 243 KB
/
index.json
1
[{"categories":["Journal"],"content":" Emu Ostrich Ferris wheel🎡 Duck🦆 Five Pagoda Temple🛕 Zebra🦓 Bear🐻 Polar bear🐻❄️ Flamingo🦩 Duck🦆 Bird🐦⬛ Pigeon🐦 Sunset🌇 ","date":"2024-12-03","objectID":"/autumn-in-beijing/:0:0","tags":["Stroll"],"title":"Autumn🍂 in Beijing","uri":"/autumn-in-beijing/"},{"categories":["Note"],"content":" 30 Days of JavaScript https://leetcode.com/studyplan/30-days-of-javascript/ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:0:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2667. Create Hello World Function /** * @return {Function} */ var createHelloWorld = function() { return function(...args) { return \"Hello World\"; } }; /** * const f = createHelloWorld(); * f(); // \"Hello World\" */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:1:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2623. Memoize /** * @param {Function} fn * @return {Function} */ function memoize(fn) { const memory = new Map(); return function (...args) { let key = fn.name; for (let arg of args) key += '.' + arg; if (memory.has(key)) return memory.get(key); else { const value = fn(...args); memory.set(key, value); return value; } } } /** * let callCount = 0; * const memoizedFn = memoize(function (a, b) { * callCount += 1; * return a + b; * }) * memoizedFn(2, 3) // 5 * memoizedFn(2, 3) // 5 * console.log(callCount) // 1 */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:2:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2637. Promise Time Limit /** * @param {Function} fn * @param {number} t * @return {Function} */ var timeLimit = function (fn, t) { return async function (...args) { const timeoutPromise = new Promise((_, reject) =\u003e { setTimeout(() =\u003e { reject(\"Time Limit Exceeded\"); }, t); }); return Promise.race([fn(...args), timeoutPromise]); } }; /** * const limited = timeLimit((t) =\u003e new Promise(res =\u003e setTimeout(res, t)), 100); * limited(150).catch(console.log) // \"Time Limit Exceeded\" at t=100ms */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:3:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2703. Return Length of Arguments Passed /** * @param {...(null|boolean|number|string|Array|Object)} args * @return {number} */ var argumentsLength = function (...args) { return args.length; }; /** * argumentsLength(1, 2, 3); // 3 */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:4:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2629. Function Composition /** * @param {Function[]} functions * @return {Function} */ var compose = function (functions) { return function (x) { if (functions.length === 0) return x; else { let res = functions[functions.length - 1](x); for (let i = functions.length - 2; i \u003e= 0; --i) res = functions[i](res); return res; } } }; /** * const fn = compose([x =\u003e x + 1, x =\u003e 2 * x]) * fn(4) // 9 */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:5:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2622. Cache With Time Limit var TimeLimitedCache = function () { this.cache = new Map(); this.timer = new Map(); }; /** * @param {number} key * @param {number} value * @param {number} duration time until expiration in ms * @return {boolean} if un-expired key already existed */ TimeLimitedCache.prototype.set = function (key, value, duration) { const keyExists = this.cache.has(key); if (keyExists) { clearTimeout(this.timer.get(key)); } this.cache.set(key, value); const timer = setTimeout(() =\u003e { this.cache.delete(key); this.timer.delete(key); }, duration); this.timer.set(key, timer); return keyExists; }; /** * @param {number} key * @return {number} value associated with key */ TimeLimitedCache.prototype.get = function (key) { if (this.cache.has(key)) { return this.cache.get(key); } else { return -1; } }; /** * @return {number} count of non-expired keys */ TimeLimitedCache.prototype.count = function () { return this.cache.size; }; /** * const timeLimitedCache = new TimeLimitedCache() * timeLimitedCache.set(1, 42, 1000); // false * timeLimitedCache.get(1) // 42 * timeLimitedCache.count() // 1 */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:6:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2627. Debounce /** * @param {Function} fn * @param {number} t milliseconds * @return {Function} */ var debounce = function (fn, t) { let timer = null; return function (...args) { if (timer) clearTimeout(timer); timer = setTimeout(() =\u003e { fn(...args); }, t); } }; /** * const log = debounce(console.log, 100); * log('Hello'); // cancelled * log('Hello'); // cancelled * log('Hello'); // Logged at t=100ms */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:7:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2721. Execute Asynchronous Functions in Parallel /** * @param {Array\u003cFunction\u003e} functions * @return {Promise\u003cany\u003e} */ var promiseAll = function (functions) { return new Promise((resolve, reject) =\u003e { const results = []; let cnt = 0; functions.forEach((func, index) =\u003e { func().then((res) =\u003e { results[index] = res; ++cnt; if (cnt === functions.length) resolve(results); }).catch((err) =\u003e { reject(err); }) }) }) }; /** * const promise = promiseAll([() =\u003e new Promise(res =\u003e res(42))]) * promise.then(console.log); // [42] */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:8:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2723. Add Two Promises /** * @param {Promise} promise1 * @param {Promise} promise2 * @return {Promise} */ var addTwoPromises = async function (promise1, promise2) { const a = await promise1; const b = await promise2; return a + b; }; /** * addTwoPromises(Promise.resolve(2), Promise.resolve(2)) * .then(console.log); // 4 */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:9:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2621. Sleep /** * @param {number} millis * @return {Promise} */ async function sleep(millis) { return new Promise((resolve, reject) =\u003e { setTimeout(() =\u003e { resolve(0) }, millis); }); } /** * let t = Date.now() * sleep(100).then(() =\u003e console.log(Date.now() - t)) // 100 */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:10:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2715. Timeout Cancellation /** * @param {Function} fn * @param {Array} args * @param {number} t * @return {Function} */ var cancellable = function (fn, args, t) { const flag = true; setTimeout(() =\u003e { if (flag) fn(...args); }, t); return function () { flag = false; } }; /** * const result = []; * * const fn = (x) =\u003e x * 5; * const args = [2], t = 20, cancelTimeMs = 50; * * const start = performance.now(); * * const log = (...argsArr) =\u003e { * const diff = Math.floor(performance.now() - start); * result.push({\"time\": diff, \"returned\": fn(...argsArr)}); * } * * const cancel = cancellable(log, args, t); * * const maxT = Math.max(t, cancelTimeMs); * * setTimeout(cancel, cancelTimeMs); * * setTimeout(() =\u003e { * console.log(result); // [{\"time\":20,\"returned\":10}] * }, maxT + 15) */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:11:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2725. Interval Cancellation /** * @param {Function} fn * @param {Array} args * @param {number} t * @return {Function} */ var cancellable = function (fn, args, t) { fn(...args); const timer = setInterval(() =\u003e { fn(...args); }, t); return function () { clearInterval(timer); } }; /** * const result = []; * * const fn = (x) =\u003e x * 2; * const args = [4], t = 35, cancelTimeMs = 190; * * const start = performance.now(); * * const log = (...argsArr) =\u003e { * const diff = Math.floor(performance.now() - start); * result.push({\"time\": diff, \"returned\": fn(...argsArr)}); * } * * const cancel = cancellable(log, args, t); * * setTimeout(cancel, cancelTimeMs); * * setTimeout(() =\u003e { * console.log(result); // [ * // {\"time\":0,\"returned\":8}, * // {\"time\":35,\"returned\":8}, * // {\"time\":70,\"returned\":8}, * // {\"time\":105,\"returned\":8}, * // {\"time\":140,\"returned\":8}, * // {\"time\":175,\"returned\":8} * // ] * }, cancelTimeMs + t + 15) */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:12:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2631. Group By /** * @param {Function} fn * @return {Object} */ Array.prototype.groupBy = function (fn) { const res = {}; for (let i = 0; i \u003c this.length; ++i) { const key = fn(this[i]); if (res[key]) res[key].push(this[i]); else res[key] = [this[i]]; } return res; }; /** * [1,2,3].groupBy(String) // {\"1\":[1],\"2\":[2],\"3\":[3]} */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:13:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2625. Flatten Deeply Nested Array /** * @param {Array} arr * @param {number} depth * @return {Array} */ // var flat = function (arr, n) { // if (n === 0) return arr; // return arr.reduce((res, item) =\u003e { // if (Array.isArray(item)) return res.concat(flat(item, n - 1)); // else return res.concat(item); // }, []); // }; var flat = function (arr, n) { if (n === 0) return arr; const res = []; const stack = arr.map(a =\u003e [a, n]); while (stack.length) { const [cur, depth] = stack.pop(); if (Array.isArray(cur) \u0026\u0026 depth \u003e 0) { stack.push(...cur.map(c =\u003e [c, depth - 1])); } else { res.push(cur); } } return res.reverse(); }; ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:14:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2705. Compact Object /** * @param {Object|Array} obj * @return {Object|Array} */ var compactObject = function (obj) { if (Array.isArray(obj)) { let i = 0; while (i \u003c obj.length) { if (Array.isArray(obj[i]) || obj[i] instanceof Object) { obj[i] = compactObject(obj[i]); } if (Boolean(obj[i]) === false) obj.splice(i, 1); else ++i; } return obj; } else { let keys = Object.keys(obj); for (let key of keys) { let value = obj[key]; if (Array.isArray(value) || value instanceof Object) { value = compactObject(value); } if (Boolean(value) === false) delete obj[key]; } return obj; } }; ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:15:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2694. Event Emitter class EventEmitter { constructor() { this.event = new Map(); } /** * @param {string} eventName * @param {Function} callback * @return {Object} */ subscribe(eventName, callback) { let callbacks = undefined; if (this.event.has(eventName)) { callbacks = this.event.get(eventName); } else { callbacks = []; } callbacks.push(callback); this.event.set(eventName, callbacks); const index = callbacks.length - 1; return { unsubscribe: () =\u003e { if (this.event.has(eventName)) { const callbacks = this.event.get(eventName); callbacks[index] = null; this.event.set(eventName, callbacks); } } }; } /** * @param {string} eventName * @param {Array} args * @return {Array} */ emit(eventName, args = []) { if (this.event.has(eventName)) { const results = []; const callbacks = this.event.get(eventName); for (let callback of callbacks) { if (callback !== null) { const res = callback(...args); results.push(res); } } return results; } else return []; } } /** * const emitter = new EventEmitter(); * * // Subscribe to the onClick event with onClickCallback * function onClickCallback() { return 99 } * const sub = emitter.subscribe('onClick', onClickCallback); * * emitter.emit('onClick'); // [99] * sub.unsubscribe(); // undefined * emitter.emit('onClick'); // [] */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:16:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2722. Join Two Arrays by ID /** * @param {Array} arr1 * @param {Array} arr2 * @return {Array} */ var join = function (arr1, arr2) { const res = []; const map = new Map(); for (let obj of arr1) map.set(obj.id, { ...obj }); for (let obj of arr2) { const id = obj.id; if (map.has(id)) { const o = map.get(id); for (let key in obj) o[key] = obj[key]; } else map.set(id, { ...obj }); } for (let value of map.values()) res.push(value); res.sort((a, b) =\u003e a.id - b.id); return res; }; ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:17:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2695. Array Wrapper /** * @param {number[]} nums * @return {void} */ var ArrayWrapper = function (nums) { this.nums = [...nums] }; /** * @return {number} */ ArrayWrapper.prototype.valueOf = function () { if (this.nums.length === 0) return 0; return this.nums.reduce((sum, num) =\u003e { return sum + num }, 0); } /** * @return {string} */ ArrayWrapper.prototype.toString = function () { let str = '['; for (const num of this.nums) { if (str !== '[') str += ','; str += num; } return str + ']'; } /** * const obj1 = new ArrayWrapper([1,2]); * const obj2 = new ArrayWrapper([3,4]); * obj1 + obj2; // 10 * String(obj1); // \"[1,2]\" * String(obj2); // \"[3,4]\" */ ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:18:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"2726. Calculator with Method Chaining class Calculator { /** * @param {number} value */ constructor(value) { this.value = value; } /** * @param {number} value * @return {Calculator} */ add(value) { this.value += value; return this; } /** * @param {number} value * @return {Calculator} */ subtract(value) { this.value -= value; return this; } /** * @param {number} value * @return {Calculator} */ multiply(value) { this.value *= value; return this; } /** * @param {number} value * @return {Calculator} */ divide(value) { if (value === 0) throw new Error(\"Division by zero is not allowed\"); this.value /= value; return this; } /** * @param {number} value * @return {Calculator} */ power(value) { this.value = Math.pow(this.value, value); return this; } /** * @return {number} */ getResult() { return this.value; } } ","date":"2024-10-02","objectID":"/leetcode-30-days-of-javascript/:19:0","tags":["JavaScript","LeetCode","Frontend"],"title":"LeetCode: 30 Days of JavaScript","uri":"/leetcode-30-days-of-javascript/"},{"categories":["Note"],"content":"402. Remove K Digits function removeKdigits(num: string, k: number): string { if (k === num.length) return \"0\"; let stack: string[] = []; let removed = 0; for (let i = 0; i \u003c num.length; ++i) { while (stack.length \u0026\u0026 removed \u003c k \u0026\u0026 num[i] \u003c stack[stack.length - 1]) { ++removed; stack.pop(); } stack.push(num[i]); } while (removed \u003c k) { stack.pop(); ++removed; } let flag = false; for (let i = 0; i \u003c stack.length; ++i) { if (stack[i] !== '0') { flag = true; stack = stack.slice(i); break; } } if (!flag) return \"0\"; else return stack.join(''); }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:1","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"41. First Missing Positive function firstMissingPositive(nums: number[]): number { let len = nums.length; for (let i = 0; i \u003c len; ++i) { while (nums[i] \u003e 0 \u0026\u0026 nums[i] \u003c len \u0026\u0026 i !== nums[i] - 1) { let index = nums[i] - 1; let num = nums[index]; if (num === nums[i]) break; nums[index] = nums[i]; nums[i] = num; } } for (let i = 0; i \u003c len; ++i) { if (nums[i] !== i + 1) return i + 1; } return nums[len - 1] + 1; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:2","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"42. Trapping Rain Water function trap(height: number[]): number { let res = 0; let left = 0; let right = height.length - 1; let level = 0; while (left \u003c right) { let lower = height[left] \u003e height[right] ? height[right--] : height[left++]; level = Math.max(lower, level); res += level - lower; } return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:3","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"1. Two Sum function twoSum(nums: number[], target: number): number[] { let result: number[] = []; let index: Map\u003cnumber, number[]\u003e = new Map(); for (let i = 0; i \u003c nums.length; ++i) { if (index.has(nums[i])) { index.set(nums[i], [...index.get(nums[i]), i]); } else { index.set(nums[i], [i]); } let n = target - nums[i]; if (n === nums[i]) { if (index.get(nums[i]).length \u003e= 2) { result = [index.get(nums[i])[0], index.get(nums[i])[1]]; break; } } else { if (index.has(n)) { result = [index.get(n)[0], index.get(nums[i])[0]]; break; } } } return result; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:4","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"206. Reverse Linked List function reverseList(head: ListNode | null): ListNode | null { if (!head || !head.next) return head; let prior = head; let ptr = prior.next; prior.next = null; while (ptr) { let next = ptr.next; ptr.next = prior; head = ptr; prior = ptr; ptr = next; } return head; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:5","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"206. Reverse Linked List function convertToTitle(columnNumber: number): string { let num = columnNumber.toString(26); let res = ''; let A = 'A'.charCodeAt(0); let carry = 0; for (let i = num.length - 1; i \u003e= 0; --i) { let n = 0; if (num[i].charCodeAt(0) \u003e= A) n = 10 + (num[i].toUpperCase()).charCodeAt(0) - A; else n = +num[i]; if (n === 0) { n = 26; if (carry) { n -= carry; carry = 0; } carry += 1; res = String.fromCharCode(A + n - 1) + res; continue; } if (carry) { if (n \u003e= carry) { n -= carry; carry = 0; } else { carry -= n; n = 0; } } if (n === 0) { if (i === 0) break; else { n = 26; carry += 1; } } res = String.fromCharCode(A + n - 1) + res; } return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:6","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"239. Sliding Window Maximum /** * @param {number[]} nums * @param {number} k * @return {number[]} */ var maxSlidingWindow = function (nums, k) { let res = []; let window = []; for (let i = 0; i \u003c nums.length; ++i) { if (window[0] \u003c i - k + 1) window.shift(); if (nums[i] \u003c nums[window[window.length - 1]]) window.push(i); else { while (window.length \u003e 0 \u0026\u0026 nums[window[window.length - 1]] \u003c= nums[i]) window.pop(); window.push(i); } if (i \u003e= k - 1) res.push(nums[window[0]]); } return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:7","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"1472. Design Browser History /** * @param {string} homepage */ var BrowserHistory = function (homepage) { this.head = { url: homepage, next: null, prior: null }; this.current = this.head; }; /** * @param {string} url * @return {void} */ BrowserHistory.prototype.visit = function (url) { let next = { url: url, next: null, prior: this.current }; this.current.next = next; this.current = this.current.next; }; /** * @param {number} steps * @return {string} */ BrowserHistory.prototype.back = function (steps) { let num = 0; while (this.current !== this.head \u0026\u0026 num \u003c steps) { this.current = this.current.prior; ++num; } return this.current.url; }; /** * @param {number} steps * @return {string} */ BrowserHistory.prototype.forward = function (steps) { let num = 0; while (this.current.next !== null \u0026\u0026 num \u003c steps) { this.current = this.current.next; ++num; } return this.current.url; }; /** * Your BrowserHistory object will be instantiated and called as such: * var obj = new BrowserHistory(homepage) * obj.visit(url) * var param_2 = obj.back(steps) * var param_3 = obj.forward(steps) */ ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:8","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"209. Minimum Size Subarray Sum /** * @param {number} target * @param {number[]} nums * @return {number} */ var minSubArrayLen = function (target, nums) { let left = 0; let len = nums.length; let res = Infinity; let sum = 0; for (let right = 0; right \u003c len; ++right) { sum += nums[right]; while (sum \u003e= target) { res = Math.min(res, right - left + 1); sum -= nums[left]; ++left; } } return res === Infinity ? 0 : res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:9","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"16. 3Sum Closest /** * @param {number[]} nums * @param {number} target * @return {number} */ var threeSumClosest = function (nums, target) { nums.sort((a, b) =\u003e a - b); let abs = Infinity; let res = target; for (let i = 0; i \u003c nums.length; ++i) { let left = i + 1; let right = nums.length - 1; while (left \u003c right) { let sum = nums[i] + nums[left] + nums[right]; if (Math.abs(sum - target) \u003c abs) { abs = Math.abs(sum - target); res = sum; } if (sum === target) return res; else if (sum \u003c target) ++left; else --right; } } return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:10","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"88. Merge Sorted Array /** * @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) { let i = m - 1; let j = n - 1; let k = nums1.length - 1; while (i \u003e= 0 || j \u003e= 0) { if (i \u003c 0 \u0026\u0026 j \u003e= 0 || nums2[j] \u003e nums1[i]) { nums1[k] = nums2[j]; --j; } else { nums1[k] = nums1[i]; --i; } --k; } }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:11","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"678. Valid Parenthesis String /** * @param {string} s * @return {boolean} */ var checkValidString = function (s) { let left = []; let asterisk = []; let res = true; for (let i = 0; i \u003c s.length; ++i) { if (s[i] === '(') left.push(i); else if (s[i] === '*') asterisk.push(i); else { if (left.length \u003e 0) left.pop(); else if (asterisk.length \u003e 0) asterisk.pop(); else { res = false; break; } } } if (res === true \u0026\u0026 left.length \u003e 0) { if (asterisk.length \u003e= left.length) { while (left.length){ let l = left.pop(); let a = asterisk.pop(); if (a \u003c= l) { res = false; break; } } } else res = false; } return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:12","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"1556. Thousand Separator /** * @param {number} n * @return {string} */ var thousandSeparator = function (n) { if (n \u003c 1000) return n.toString(); let res = \"\"; let s = n.toString(); let cnt = 0; for (let i = s.length - 1; i \u003e= 0; --i) { ++cnt; res = s[i] + res; if (cnt % 3 === 0 \u0026\u0026 i !== 0) res = '.' + res; } return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:13","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"39. Combination Sum /** * @param {number[]} candidates * @param {number} target * @return {number[][]} */ let set = new Set(); let res = []; let t = 0; let c = []; function dfs(nums, sum) { if (sum === t) { let str = \"\"; for (let n of nums) str += n + \",\"; if (!set.has(str)) { res.push([...nums]); set.add(str); } return; } for (let i = 0; i \u003c c.length; ++i) { if (sum + c[i] \u003e t) break; if (nums.length === 0 || c[i] \u003e= nums[nums.length - 1]) { nums.push(c[i]); sum += c[i]; dfs(nums, sum); nums.pop(); sum -= c[i]; } } } var combinationSum = function (candidates, target) { set.clear(); res = []; t = target; c = candidates; candidates.sort((a, b) =\u003e a - b); dfs([], 0); return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:14","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"20. Valid Parentheses /** * @param {string} s * @return {boolean} */ var isValid = function (s) { let stack = []; let res = true; for (let i = 0; i \u003c s.length; ++i) { if (s[i] === '(') stack.push('('); else if (s[i] === '{') stack.push('{'); else if (s[i] === '[') stack.push('['); else { let top = stack.pop(); if (!(top === '(' \u0026\u0026 s[i] === ')' || top === '{' \u0026\u0026 s[i] === '}' || top === '[' \u0026\u0026 s[i] === ']')) { res = false; break; } } } if (stack.length) res = false; return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:15","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"415. Add Strings /** * @param {string} num1 * @param {string} num2 * @return {string} */ // var addStrings = function (num1, num2) { // return (BigInt(num1) + BigInt(num2)).toString(); // }; var addStrings = function (num1, num2) { let a = [], b = []; if (num1.length \u003c num2.length) { let num3 = num1; num1 = num2; num2 = num3; } for (let i = 0; i \u003c num1.length; ++i) a.push(+num1[i]); for (let i = 0; i \u003c num2.length; ++i) b.push(+num2[i]); let x = num1.length - 1, y = num2.length - 1; while (y \u003e= 0) { a[x] += b[y]; --x; --y; } x = num1.length - 1; while (x \u003e 0) { if (a[x] \u003e= 10) { a[x - 1] += 1; a[x] -= 10; } --x; } let first = a[0]; if (first \u003e= 10) a[0] -= 10; if (first \u003e= 10) return 1 + a.join(''); else return a.join(''); }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:16","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"22. Generate Parentheses /** * @param {number} n * @return {string[]} */ var generateParenthesis = function (n) { let res = []; function dfs(sum, l, p, str) { if (sum === n) { res.push(str.join('')); return; } if (l \u003c n) { l += 1; p += 1; str.push('(') dfs(sum, l, p, str); l -= 1; p -= 1; str.pop(); } if (p \u003e 0) { p -= 1; str.push(')'); sum += 1; dfs(sum, l, p, str); p += 1; str.pop(); sum -= 1; } } dfs(0, 0, 0, []); return res; }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:17","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"75. Sort Colors /** * @param {number[]} nums * @return {void} Do not return anything, modify nums in-place instead. */ var sortColors = function (nums) { for (let i = 0; i \u003c nums.length; ++i) { let flag = false; for (let j = 1; j \u003c= nums.length - i; ++j) { if (nums[j] \u003c nums[j - 1]) { flag = true; let tmp = nums[j]; nums[j] = nums[j - 1]; nums[j - 1] = tmp; } } if (!flag) break; } }; ","date":"2024-05-24","objectID":"/recent-leetcode-problem-solving-record/:0:18","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Problem-Solving Record","uri":"/recent-leetcode-problem-solving-record/"},{"categories":["Note"],"content":"I accidentally discovered the built-in sips command line tool in macOS, which is used to process and manipulate images. It supports multiple image formats and provides some common image processing functions such as compression, resizing, rotation, etc. ","date":"2024-04-27","objectID":"/sips-tool-in-macos/:0:0","tags":["command line tools","macOS"],"title":"sips: MacOS built-in image processing tool","uri":"/sips-tool-in-macos/"},{"categories":["Note"],"content":"Some examples Compress image sips -s format jpeg ~/image.jpeg --out ~/image.jpeg --setProperty formatOptions 50% Change image size sips --resampleWidth 500 --resampleHeight 300 input.jpg --out output.jpg Resize image proportionally sips --resampleHeightWidth 500 300 input.jpg --out output.jpg Rotate image sips --rotate 90 input.jpg --out output.jpg Convert image format sips -s format jpeg input.png --out output.jpg View image information sips -g all input.jpg ","date":"2024-04-27","objectID":"/sips-tool-in-macos/:1:0","tags":["command line tools","macOS"],"title":"sips: MacOS built-in image processing tool","uri":"/sips-tool-in-macos/"},{"categories":["Note"],"content":"A few days ago, I suddenly found that Spotlight could not search anything, and the settings application could not search for settings items either. It seems that this phenomenon has occurred before, and this time I finally noticed it. At first, I thought it was a problem with the index of Spotlight, and I reset the index several times according to the methods on the Internet, such as executing sudo mdutil -a -E. It was normal immediately after the reset, but it didn’t work after a while, and I don’t know what went wrong. After trying for several days, I finally can reproduce this problem stably: only when I unlock the computer using Touch ID, the Spotlight search will fail. If I unlock with a password, the Spotlight search can work normally, or after unlocking with Touch ID, find an opportunity to enter the password once, such as executing the sudo command, the Spotlight search will immediately work normally. Because using a password or Touch ID is a very common operation, it is difficult to think that the problem lies here. I tried to create a new user, and it was normal, but after importing the previous Time Machine backup using the migration assistant, this problem reappeared. I searched online and found that someone on the Alfred forum encountered the same problem as me, Spotlight indexing issues in Ventura 13.6.1, but there is no solution. I reported it on the macOS website and no more response. I think as long as I automatically enter the password once after unlocking with Touch ID, this problem can be alleviated. I used brew to install sleepwatcher and expect respectively, used to monitor computer sleep and automatically enter the password. I wrote a few scripts: ","date":"2024-04-26","objectID":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/:0:0","tags":["macOS","command line tools"],"title":"Spotlight Not Working Properly With Touch ID Unlock on MacOS","uri":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/"},{"categories":["Note"],"content":"spotlight.exp #! /usr/bin/expect -f set script_dir [file dir [info script]] set password [exec $script_dir/get_password.sh] spawn sudo mdutil -vsa expect \"Password:\" send \"$password\\r\" interact ","date":"2024-04-26","objectID":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/:0:1","tags":["macOS","command line tools"],"title":"Spotlight Not Working Properly With Touch ID Unlock on MacOS","uri":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/"},{"categories":["Note"],"content":"get_password.sh #!/bin/sh password=$(security find-generic-password -a '$YOUR_USER_NAME' -s 'SleepwatcherPassword' -w) echo $password Here you need to execute security add-generic-password -a '$YOUR_USER_NAME' -s 'SleepwatcherPassword' -w '$YOUR_PASSWORD' in advance to save the password. ","date":"2024-04-26","objectID":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/:0:2","tags":["macOS","command line tools"],"title":"Spotlight Not Working Properly With Touch ID Unlock on MacOS","uri":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/"},{"categories":["Note"],"content":".wakeup #!/bin/sh expect /path/to/spotlight.exp In this way, every time the computer wakes up from sleep, sleepwatcher will automatically execute the .wakeup script, automatically enter the password, so that the Spotlight search can work normally. But if you unlock with Touch ID after locking without sleeping, the problem will still occur, but this situation is relatively rare. ","date":"2024-04-26","objectID":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/:0:3","tags":["macOS","command line tools"],"title":"Spotlight Not Working Properly With Touch ID Unlock on MacOS","uri":"/spotlight-not-working-properly-with-touch-id-unlock-on-macos/"},{"categories":["Note"],"content":"LeetCode Top Interview 150 ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:0","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"9. Palindrome Number function isPalindrome(x: number): boolean { let str = x.toString(); let len = str.length; for (let i = 0; i \u003c len / 2; ++i) { if (str[i] !== str[len - i - 1]) return false; } return true; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:1","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"69. Sqrt(x) function mySqrt(x: number): number { for (let i = 1; i \u003c= x; ++i) { if (i * i \u003e x) return i - 1; else if (i * i === x) return i; else continue; } return x; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:2","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"169. Majority Element function majorityElement(nums: number[]): number { let res = 0, cnt = 0; for (let i = 0; i \u003c nums.length; ++i) { if (cnt === 0) { res = nums[i]; ++cnt; } else if (nums[i] === res) ++cnt else --cnt; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:3","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"125. Valid Palindrome function isPalindrome(s: string): boolean { let str = \"\"; let a = \"a\".charCodeAt(0), z = \"z\".charCodeAt(0); let A = \"A\".charCodeAt(0), Z = \"Z\".charCodeAt(0); let _0 = \"0\".charCodeAt(0), _9 = \"9\".charCodeAt(0); for (let c of s) { let code = c.charCodeAt(0); if (code \u003e= a \u0026\u0026 code \u003c= z || code \u003e= _0 \u0026\u0026 code \u003c= _9) str += c; else if (code \u003e= A \u0026\u0026 code \u003c= Z) str += c.toLowerCase(); } let left = 0, right = str.length - 1; while (left \u003c= right) { if (str[left] !== str[right]) return false; ++left; --right; } return true; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:4","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"209. Minimum Size Subarray Sum function minSubArrayLen(target: number, nums: number[]): number { let left = 0, sum = 0, len = nums.length, res = Infinity; for (let right = 0; right \u003c len; ++right) { sum += nums[right]; while (sum \u003e= target) { res = Math.min(res, right - left + 1); sum -= nums[left]; left += 1; } } if (res === Infinity) return 0; else return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:5","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"36. Valid Sudoku function isValidSudoku(board: string[][]): boolean { let rows: Map\u003cstring, number\u003e[] = [], cols: Map\u003cstring, number\u003e[] = [], boxes: Map\u003cstring, number\u003e[] = []; for (let i = 0; i \u003c 9; i++) { rows[i] = new Map(); cols[i] = new Map(); boxes[i] = new Map(); } for (let i = 0; i \u003c 9; ++i) { for (let j = 0; j \u003c 9; ++j) { let s = board[i][j]; if (s === \".\") continue; if (rows[i].has(s)) return false; else rows[i].set(s, 1); if (cols[j].has(s)) return false; else cols[j].set(s, 1); let k = Math.trunc(i / 3) * 3 + Math.trunc(j / 3); if (boxes[k].has(s)) return false; else boxes[k].set(s, 1); } } return true; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:6","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"205. Isomorphic Strings function isIsomorphic(s: string, t: string): boolean { let ms = new Map(), mt = new Map(); for (let i = 0; i \u003c s.length; ++i) { if (ms.has(s[i])) { if (ms.get(s[i]) !== t[i]) return false; } else ms.set(s[i], t[i]); if (mt.has(t[i])) { if (mt.get(t[i]) !== s[i]) return false; } else mt.set(t[i], s[i]); } return true; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:7","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"228. Summary Ranges function summaryRanges(nums: number[]): string[] { let res = []; let left = 0, right = 0, len = nums.length; while (left \u003c len \u0026\u0026 right \u003c len) { ++right; if (right \u003e= len || nums[right] - nums[left] \u003e right - left) { if (right - 1 === left) res.push(nums[left].toString()); else res.push(nums[left].toString() + \"-\u003e\" + nums[right - 1].toString()); left = right; } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:8","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"71. Simplify Path function simplifyPath(path: string): string { let dirs = [\"\"]; let dir = \"\"; let flag = false; for (let c of path) { if (flag === false) { if (c !== \"/\") { dir = c; flag = true; } } else { if (c !== \"/\") dir += c; else { if (dir === \"..\") { if (dirs.length \u003e 1) dirs.pop(); } else if (dir !== \".\") dirs.push(dir); flag = false; } } } if (flag === true) { if (dir === \"..\") { if (dirs.length \u003e 1) dirs.pop(); } else if (dir !== \".\") dirs.push(dir); flag = false; } if (dirs.length === 1) return \"/\"; else return dirs.join(\"/\") }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:9","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"92. Reverse Linked List II function reverseBetween(head: ListNode | null, left: number, right: number): ListNode | null { if (left === right || head === null) return head; let nums = [], cnt = 0, ptr = head; while (true) { ++cnt; if (cnt \u003e= left \u0026\u0026 cnt \u003c= right) nums.push(ptr.val); if (ptr.next) ptr = ptr.next; else break; } ptr = head; cnt = 0; let len = nums.length; while (true) { ++cnt; if (cnt \u003e= left \u0026\u0026 cnt \u003c= right) ptr.val = nums[--len]; if (ptr.next) ptr = ptr.next; else break; } return head; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:10","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"104. Maximum Depth of Binary Tree // class TreeNode { // val: number // left: TreeNode | null // right: TreeNode | null // constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { // this.val = (val === undefined ? 0 : val) // this.left = (left === undefined ? null : left) // this.right = (right === undefined ? null : right) // } // } let res = 0; function dfs(node: TreeNode | null, depth: number): void { if (node === null) return; ++depth; if (depth \u003e res) res = depth; dfs(node.left, depth); dfs(node.right, depth); } function maxDepth(root: TreeNode | null): number { res = 0; dfs(root, 0); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:11","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"637. Average of Levels in Binary Tree // class TreeNode { // val: number // left: TreeNode | null // right: TreeNode | null // constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { // this.val = (val === undefined ? 0 : val) // this.left = (left === undefined ? null : left) // this.right = (right === undefined ? null : right) // } // } function averageOfLevels(root: TreeNode | null): number[] { let queue = []; let res = [], sum = 0, cnt = 0; queue.push(root); while (queue.length \u003e 0) { sum = 0; cnt = 0; let tmp = []; for (let node of queue) { sum += node!.val; ++cnt; if (node!.left !== null) tmp.push(node!.left); if (node!.right !== null) tmp.push(node!.right); } res.push(sum / cnt); queue = tmp; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:12","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"530. Minimum Absolute Difference in BST // class TreeNode { // val: number // left: TreeNode | null // right: TreeNode | null // constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { // this.val = (val === undefined ? 0 : val) // this.left = (left === undefined ? null : left) // this.right = (right === undefined ? null : right) // } // } let vals: number[] = []; function dfs(node: TreeNode | null): void { if (node === null) return; vals.push(node.val); dfs(node.left); dfs(node.right); } function getMinimumDifference(root: TreeNode | null): number { vals = []; dfs(root); vals.sort((a, b) =\u003e a - b); let len = vals.length; let res = Infinity; for (let i = 1; i \u003c len; ++i) { let d = vals[i] - vals[i - 1]; if (d \u003c res) res = d; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:13","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"200. Number of Islands let s = new Set(); function dfs(i: number, j: number, m: number, n: number, grid: string[][]): void { s.add(i * n + j); if (i - 1 \u003e= 0 \u0026\u0026 grid[i - 1][j] === \"1\" \u0026\u0026 !s.has((i - 1) * n + j)) dfs(i - 1, j, m, n, grid); if (i + 1 \u003c m \u0026\u0026 grid[i + 1][j] === \"1\" \u0026\u0026 !s.has((i + 1) * n + j)) dfs(i + 1, j, m, n, grid); if (j - 1 \u003e= 0 \u0026\u0026 grid[i][j - 1] === \"1\" \u0026\u0026 !s.has(i * n + (j - 1))) dfs(i, j - 1, m, n, grid); if (j + 1 \u003c n \u0026\u0026 grid[i][j + 1] === \"1\" \u0026\u0026 !s.has(i * n + (j + 1))) dfs(i, j + 1, m, n, grid); } function numIslands(grid: string[][]): number { s = new Set(); let res = 0; let m = grid.length, n = grid[0].length; for (let i = 0; i \u003c m; ++i) { for (let j = 0; j \u003c n; ++j) { if (grid[i][j] === \"1\" \u0026\u0026 !s.has(i * n + j)) { dfs(i, j, m, n, grid); ++res; } } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:14","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"208. Implement Trie (Prefix Tree) interface trieNode { val: string; isEnd: boolean; sons: trieNode[]; }; class Trie { root: trieNode; constructor() { this.root = { val: \"\", isEnd: false, sons: [], }; } insert(word: string): void { let ptr = this.root; let len = word.length; for (let i = 0; i \u003c len; ++i) { let flag = false; let sons = ptr.sons; for (let son of sons) { if (son.val === word[i] \u0026\u0026 (son.isEnd === false \u0026\u0026 i \u003c len - 1 || son.isEnd === true \u0026\u0026 i === len - 1)) { flag = true; ptr = son; break; } } if (!flag) { let newSon = { val: word[i], isEnd: i === len - 1 ? true : false, sons: [], }; ptr.sons.push(newSon); ptr = newSon; } } } search(word: string): boolean { let res = true; let ptr = this.root; let len = word.length; for (let i = 0; i \u003c len; ++i) { let flag = false; let sons = ptr.sons; for (let son of sons) { if (son.val === word[i] \u0026\u0026 (son.isEnd === false \u0026\u0026 i \u003c len - 1 || son.isEnd === true \u0026\u0026 i === len - 1)) { flag = true; ptr = son; break; } } if (!flag) { res = false; break; } } return res; } startsWith(prefix: string): boolean { let res = true; let ptr = this.root; let len = prefix.length; for (let i = 0; i \u003c len; ++i) { let flag = false; let sons = ptr.sons; for (let son of sons) { if (son.val === prefix[i] \u0026\u0026 (son.isEnd === false \u0026\u0026 i \u003c len - 1 || i === len - 1)) { flag = true; ptr = son; break; } } if (!flag) { res = false; break; } } return res; } } ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:15","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"433. Minimum Genetic Mutation let res = Infinity; function diff(a: string, b: string): number { let res = 0; for (let i = 0; i \u003c 8; ++i) { if (a[i] !== b[i]) ++res; } return res; } function dfs(gene: string, endGene: string, bank: string[], depth: number, visited: Set\u003cstring\u003e): void { if (gene === endGene) { if (depth \u003c res) res = depth; return; } for (let b of bank) { if (diff(gene, b) === 1 \u0026\u0026 !visited.has(b)) { visited.add(b); dfs(b, endGene, bank, depth + 1, visited); visited.delete(b); } } } function minMutation(startGene: string, endGene: string, bank: string[]): number { res = Infinity; dfs(startGene, endGene, bank, 0, new Set()); if (res === Infinity) return -1; else return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:16","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"77. Combinations let res: number[][]; function dfs(n: number, k: number, nums: number[], left: number) { if (nums.length === k) { res.push(nums.slice()); return; } for (let i = left; i \u003c= n; ++i) { nums.push(i); dfs(n, k, nums, i + 1); nums.pop(); } } function combine(n: number, k: number): number[][] { res = []; dfs(n, k, [], 1); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:17","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"53. Maximum Subarray function maxSubArray(nums: number[]): number { let dp = []; let len = nums.length; let res = nums[0]; dp[0] = nums[0]; for (let i = 1; i \u003c len; ++i) { dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]); if (dp[i] \u003e res) res = dp[i]; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:18","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"215. Kth Largest Element in an Array function findKthLargest(nums: number[], k: number): number { nums.sort((a, b) =\u003e b - a); return nums[k - 1]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:19","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"267. Add Binary function addBinary(a: string, b: string): string { let x = BigInt(\"0b\" + a); let y = BigInt(\"0b\" + b); let z = x + y; return z.toString(2); }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:20","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"50. Pow(x, n) function myPow(x: number, n: number): number { if (n \u003c 0) { x = 1 / x; n = -n; } let res = 1; while (n \u003e 0) { if (n % 2 === 1) res *= x; x *= x; n = Math.floor(n / 2); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:21","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"70. Climbing Stairs function climbStairs(n: number): number { let dp = []; dp[0] = 0; dp[1] = 1; dp[2] = 2; for (let i = 3; i \u003c= n; ++i) dp[i] = dp[i - 1] + dp[i - 2]; return dp[n]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:22","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"121. Best Time to Buy and Sell Stock function maxProfit(prices: number[]): number { let p = [0]; let len = prices.length; let max = 0; let sum = 0; let flag = false; for (let i = 1; i \u003c len; ++i) { p[i] = prices[i] - prices[i - 1]; if (flag) { sum += p[i]; if (sum \u003e max) max = sum; if (sum \u003c= 0) { sum = 0; flag = false; } } else { if (p[i] \u003e 0) { sum += p[i]; if (sum \u003e max) max = sum; flag = true; } } } return max; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:23","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"392. Is Subsequence function isSubsequence(s: string, t: string): boolean { let i = 0, j = 0; let l1 = s.length, l2 = t.length; while (i \u003c l1 \u0026\u0026 j \u003c l2) { if (t[j] === s[i]) { ++i; ++j; } else ++j; } if (i \u003e= l1) return true; else return false; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:24","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"3. Longest Substring Without Repeating Characters function lengthOfLongestSubstring(s: string): number { let set = new Set(); let res = 0, len = s.length, sum = 0; let t = \"\"; for (let i = 0; i \u003c len; ++i) { if (set.has(s[i])) { set.clear(); let index = t.indexOf(s[i]); t = t.substring(index + 1); for (let c of t) set.add(c); sum = t.length; } ++sum; t += s[i]; set.add(s[i]); if (sum \u003e res) res = sum; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:25","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"54. Spiral Matrix function spiralOrder(matrix: number[][]): number[] { let sum = matrix.length * matrix[0].length; let cnt = 0; let i = 0, j = 0; let res = []; let right = true, down = false, left = false, up = false; while (true) { res.push(matrix[i][j]); ++cnt; matrix[i][j] = Infinity; if (cnt \u003e= sum) break; if (right) { if (j + 1 \u003c matrix[0].length \u0026\u0026 matrix[i][j + 1] \u003c= 100) { j += 1; continue; } else { right = false; down = true; } } if (down) { if (i + 1 \u003c matrix.length \u0026\u0026 matrix[i + 1][j] \u003c= 100) { i += 1; continue; } else { down = false; left = true; } } if (left) { if (j - 1 \u003e= 0 \u0026\u0026 matrix[i][j - 1] \u003c= 100) { j -= 1; continue; } else { left = false; up = true; } } if (up) { if (i - 1 \u003e= 0 \u0026\u0026 matrix[i - 1][j] \u003c= 100) { i -= 1; continue; } else { up = false; right = true; } } if (right) { if (j + 1 \u003c matrix[0].length \u0026\u0026 matrix[i][j + 1] \u003c= 100) { j += 1; continue; } else { right = false; down = true; } } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:26","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"290. Word Pattern function wordPattern(pattern: string, s: string): boolean { let a = new Map(), b = new Map(); let str = s.split(' '); if (pattern.length !== str.length) return false; let res = true; for (let i = 0; i \u003c pattern.length; ++i) { if (a.has(pattern[i])) { if (a.get(pattern[i]) !== str[i]) { res = false; break; } } else a.set(pattern[i], str[i]); if (b.has(str[i])) { if (b.get(str[i]) !== pattern[i]) { res = false; break; } } else b.set(str[i], pattern[i]); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:27","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"56. Merge Intervals function merge(intervals: number[][]): number[][] { intervals.sort((a, b) =\u003e a[0] - b[0]); let res: number[][] = []; for (let i = 0; i \u003c intervals.length; ++i) { let len = res.length; if (len === 0 || res[len - 1][1] \u003c intervals[i][0]) res.push(intervals[i]); else res[len - 1][1] = Math.max(res[len - 1][1], intervals[i][1]); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:28","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"191. Number of 1 Bits function hammingWeight(n: number): number { let s = n.toString(2); let res = 0; for (let c of s) { if (c === \"1\") ++res; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:29","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"202. Happy Number function isHappy(n: number): boolean { let num = n; let res = false; let rec: Set\u003cnumber\u003e = new Set(); while (true) { if (num === 1) { res = true; break; } if (rec.has(num)) break; rec.add(num); let str = num.toString(); num = 0; for (let c of str) num += Math.pow(+c, 2); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:30","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"13. Roman to Integer function romanToInt(s: string): number { let m: Map\u003cstring, number\u003e = new Map(); m.set('I', 1); m.set('V', 5); m.set('X', 10); m.set('L', 50); m.set('C', 100); m.set('D', 500); m.set('M', 1000); let res = 0; let ptr = 0; while (ptr \u003c s.length) { if (ptr === s.length - 1) { res += m.get(s[ptr])!; ptr += 1; } else { if (s[ptr] === 'I') { if (s[ptr + 1] === 'V') { res += 4; ptr += 2; } else if (s[ptr + 1] === 'X') { res += 9; ptr += 2; } else { res += 1; ptr += 1; } } else if (s[ptr] === 'X') { if (s[ptr + 1] === 'L') { res += 40; ptr += 2; } else if (s[ptr + 1] === 'C') { res += 90; ptr += 2; } else { res += 10; ptr += 1; } } else if (s[ptr] === 'C') { if (s[ptr + 1] === 'D') { res += 400; ptr += 2; } else if (s[ptr + 1] === 'M') { res += 900; ptr += 2; } else { res += 100; ptr += 1; } } else { res += m.get(s[ptr])!; ptr += 1; } } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:31","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"167. Two Sum II - Input Array Is Sorted function twoSum(numbers: number[], target: number): number[] { let left = 0, right = numbers.length - 1; while (left \u003c right) { let num = numbers[left] + numbers[right]; if (num === target) break; else if (num \u003c target) ++left; else --right; } return [left + 1, right + 1]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:32","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"30. Substring with Concatenation of All Words function findSubstring(s: string, words: string[]): number[] { let res: number[] = []; let wordLen = words[0].length; let len = wordLen * words.length; let left = 0; let end = s.length; let map: Map\u003cstring, number\u003e = new Map(); for (let word of words) { let cnt = map.get(word); if (!cnt) map.set(word, 1); else map.set(word, cnt + 1); } while (left \u003c end) { if (left + len \u003e end) break; let str = s.substring(left, left + wordLen); if (map.has(str)) { let index = left + wordLen; let m: Map\u003cstring, number\u003e = new Map(); m.set(str, 1); while (str.length \u003c len) { let newStr = s.substring(index, index + wordLen); if (map.has(newStr) \u0026\u0026 (!m.has(newStr) || m.get(newStr)! \u003c map.get(newStr)!)) { str += newStr; let cnt = m.get(newStr); if (!cnt) m.set(newStr, 1); else m.set(newStr, cnt + 1); index += wordLen; } else break; } if (str.length === len) res.push(left); } ++left; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:33","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"48. Rotate Image function rotate(matrix: number[][]): void { let n = matrix.length; let m: number[][] = new Array(n).fill(undefined).map( () =\u003e new Array(n).fill(undefined) ); for (let i = 0; i \u003c n; ++i) { for (let j = 0; j \u003c n; ++j) { m[i][j] = matrix[n - 1 - j][i]; } } for (let i = 0; i \u003c n; ++i) { for (let j = 0; j \u003c n; ++j) { matrix[i][j] = m[i][j]; } } }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:34","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"242. Valid Anagram function isAnagram(s: string, t: string): boolean { if (s.length != t.length) return false; let res = true; let map: Map\u003cstring, number\u003e = new Map(); for (let char of s) { let cnt = map.get(char); if (!cnt) map.set(char, 1); else map.set(char, cnt + 1); } for (let char of t) { if (!map.has(char) || map.get(char) === 0) { res = false; break; } else map.set(char, map.get(char)! - 1); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:35","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"57. Insert Interval function insert(intervals: number[][], newInterval: number[]): number[][] { if (intervals.length === 0) return [newInterval]; let res: number[][] = []; let left = newInterval[0], right = newInterval[1]; let flag = false; let inserted = false; for (let interval of intervals) { if (inserted) { res.push(interval); continue; } if (!flag) { if (interval[1] \u003c left) res.push(interval); else if (interval[0] \u003e right) { res.push(newInterval); res.push(interval); inserted = true; } else { left = Math.min(interval[0], left); right = Math.max(interval[1], right); flag = true; } } else { if (interval[0] \u003c= right) { right = Math.max(right, interval[1]); } else { res.push([left, right]); res.push(interval); flag = false; inserted = true; } } } if (!inserted) res.push([left, right]); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:36","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"155. Min Stack interface element { val: number; min: number; } class MinStack { min: number; len: number; stack: element[]; constructor() { this.min = Infinity; this.stack = []; this.len = 0; } push(val: number): void { this.stack.push({ val: val, min: this.min }); this.len += 1; if (val \u003c this.min) this.min = val; } pop(): void { this.min = this.stack[this.len - 1].min; this.stack.pop(); this.len -= 1; } top(): number { return this.stack[this.len - 1].val; } getMin(): number { return this.min; } } ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:37","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"82. Remove Duplicates from Sorted List II function deleteDuplicates(head: ListNode | null): ListNode | null { if (!head) return null; let res: ListNode | null = null; let map: Map\u003cnumber, number\u003e = new Map(); let pos: ListNode | null = head, ptr: ListNode | null = null; while (pos) { let cnt = map.get(pos.val); if (!cnt) map.set(pos.val, 1); else map.set(pos.val, cnt + 1); pos = pos.next; } pos = head; while (pos) { if (map.get(pos.val)! \u003e 1) pos = pos.next; else { if (!res) { res = pos; ptr = res; } else { ptr!.next = pos; ptr = ptr!.next; } pos = pos.next; } } if (ptr) ptr.next = null; return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:38","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"100. Same Tree function dfs(i: TreeNode | null, j: TreeNode | null): boolean { if (!i \u0026\u0026 !j) return true; else { if (i \u0026\u0026 j \u0026\u0026 i.val === j.val \u0026\u0026 dfs(i.left, j.left) \u0026\u0026 dfs(i.right, j.right)) return true; else return false; } } function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { let i = p, j = q; return dfs(i, j); }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:39","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"226. Invert Binary Tree function dfs(node: TreeNode | null): void { if (!node) return; dfs(node.left); dfs(node.right); let tmp = node.left; node.left = node.right; node.right = tmp; } function invertTree(root: TreeNode | null): TreeNode | null { dfs(root); return root; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:40","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"101. Symmetric Tree interface node { val: number; isLeft: boolean; } let map: Map\u003cnumber, node\u003e = new Map(); let index = 0; function dfs(n: TreeNode | null, isLeft: boolean): void { if (!n) return; ++index; map.set(index, { val: n.val, isLeft }); dfs(n.left, true); dfs(n.right, false); } function dfs_1(n: TreeNode | null, isLeft: boolean): boolean { if (!n) return true; ++index; let s = map.get(index)!; return (s.val === n.val \u0026\u0026 (index === 1 || s.isLeft != isLeft)) \u0026\u0026 dfs_1(n.right, false) \u0026\u0026 dfs_1(n.left, true); } function isSymmetric(root: TreeNode | null): boolean { if (!root) return true; map = new Map(); index = 0; dfs(root, false); index = 0; return dfs_1(root, false); }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:41","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"112. Path Sum let flag = false; let target = NaN; function dfs(n: TreeNode | null, sum: number): void { if (flag || !n) return; sum += n.val; if (sum === target \u0026\u0026 !n.left \u0026\u0026 !n.right) { flag = true; return; } dfs(n.left, sum); dfs(n.right, sum); } function hasPathSum(root: TreeNode | null, targetSum: number): boolean { flag = false; target = targetSum; dfs(root, 0); return flag; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:42","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"222. Count Complete Tree Nodes let res = 0; function dfs(n: TreeNode | null): void { if (!n) return; ++res; dfs(n.left); dfs(n.right); } function countNodes(root: TreeNode | null): number { res = 0; dfs(root); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:43","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"222. Count Complete Tree Nodes function rightSideView(root: TreeNode | null): number[] { let res = []; let q = []; if (root) { q.push(root); while (q.length \u003e 0) { res.push(q[q.length - 1].val); let len = q.length; while (len) { let n = q.shift(); if (n!.left) q.push(n!.left); if (n!.right) q.push(n!.right); --len; } } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:44","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"108. Convert Sorted Array to Binary Search Tree let n: number[] = []; function dfs(left: number, right: number): TreeNode | null { if (left === right) return null; let mid = Math.floor((left + right) / 2); let e = new TreeNode(n[mid]); e.left = dfs(left, mid); e.right = dfs(mid + 1, right); return e; } function sortedArrayToBST(nums: number[]): TreeNode | null { n = nums; return dfs(0, nums.length); }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:45","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"35. Search Insert Position function searchInsert(nums: number[], target: number): number { let res = 0; let left = 0, right = nums.length; while (left \u003c right) { let mid = Math.trunc((left + right) / 2); if (nums[mid] \u003e target) right = mid; else if (nums[mid] \u003c target) left = mid + 1; else { res = mid; break; } if (left === right) { res = left; break; } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:46","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"58. Length of Last Word function lengthOfLastWord(s: string): number { let str = ''; let flag = false; for (let i = 0; i \u003c s.length; ++i) { if (!flag) { if (s[i] !== ' ') { str = s[i]; flag = true; } } else { if (s[i] === ' ') flag = false; else str += s[i]; } } return str.length; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:47","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"14. Longest Common Prefix function longestCommonPrefix(strs: string[]): string { let str = strs[0]; let len = str.length; let res = ''; for (let i = 0; i \u003c= len; ++i) { let sub = str.substring(0, i); let flag = true; for (let j = 0; j \u003c strs.length; ++j) { if (!strs[j].startsWith(sub)) { flag = false; break; } } if (flag) res = sub; else break; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:48","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"28. Find the Index of the First Occurrence in a String function strStr(haystack: string, needle: string): number { return haystack.indexOf(needle); }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:49","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"219. Contains Duplicate II function containsNearbyDuplicate(nums: number[], k: number): boolean { let map: Map\u003cnumber, number[]\u003e = new Map(); let res = false; for (let i = 0; i \u003c nums.length; ++i) { let num = nums[i]; if (map.has(num)) { let indexes = map.get(num)!; indexes!.push(i); map.set(num, indexes); } else { map.set(num, [i]); } } for (let p of map) { if (p[1].length \u003e 1) { let indexes = p[1]; for (let i = 0; i \u003c nums.length - 1; ++i) { if (indexes[i + 1] - indexes[i] \u003c= k) { res = true; break; } } } if (res === true) break; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:50","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"190. Reverse Bits function reverseBits(n: number): number { let res = 0; for (let i = 0; i \u003c 32; ++i) { res = (res \u003c\u003c 1) | (n \u0026 1); n \u003e\u003e\u003e= 1; } return res \u003e\u003e\u003e 0; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:51","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"136. Single Number function singleNumber(nums: number[]): number { let res = 0; for (let num of nums) res ^= num; return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:52","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"172. Factorial Trailing Zeroes function trailingZeroes(n: number): number { let res = 0; while (n \u003e 0) { n = Math.trunc(n / 5); res += n; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:53","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"80. Remove Duplicates from Sorted Array II function removeDuplicates(nums: number[]): number { let cnt = 0; let n = 0; let index = 0; while (index \u003c nums.length) { let num = nums[index]; if (n !== num) { n = num; cnt = 1 } else ++cnt; if (cnt \u003e= 3) nums.splice(index, 1); else ++index; } return nums.length; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:54","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"11. Container With Most Water function maxArea(height: number[]): number { let res = 0; let left = 0, right = height.length - 1; while (left \u003c right) { let area = (right - left) * Math.min(height[left], height[right]); if (area \u003e res) res = area; if (height[left] \u003c= height[right]) ++left; else --right; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:55","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"73. Set Matrix Zeroes function setZeroes(matrix: number[][]): void { let rows = matrix.length, columns = matrix[0].length; let set: Set\u003cnumber\u003e = new Set(); for (let i = 0; i \u003c rows; ++i) { for (let j = 0; j \u003c columns; ++j) { if (matrix[i][j] === 0 \u0026\u0026 !set.has(i * columns + j)) { for (let x = 0; x \u003c rows; ++x) { if (matrix[x][j] !== 0) { matrix[x][j] = 0; set.add(x * columns + j); } } for (let y = 0; y \u003c columns; ++y) { if (matrix[i][y] !== 0) { matrix[i][y] = 0; set.add(i * columns + y); } } } } } }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:56","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"49. Group Anagrams function groupAnagrams(strs: string[]): string[][] { let res: string[][] = []; let map: Map\u003cstring, string[]\u003e = new Map(); for (let i = 0; i \u003c strs.length; ++i) { let str = strs[i].split(''); str.sort(); let s = str.join(''); if (map.has(s)) { let ss = map.get(s)!; ss.push(strs[i]); map.set(s, ss); } else map.set(s, [strs[i]]); } for (let p of map) res.push(p[1]); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:57","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"452. Minimum Number of Arrows to Burst Balloons function findMinArrowShots(points: number[][]): number { points.sort( (a, b): number =\u003e { return a[1] - b[1]; } ) let res = 1; let arrow = points[0][1]; for (let i = 1; i \u003c points.length; ++i) { if (arrow \u003c points[i][0]) { ++res; arrow = points[i][1]; } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:58","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"150. Evaluate Reverse Polish Notation function evalRPN(tokens: string[]): number { let s: number[] = []; for (let str of tokens) { let token = +str; if (str !== '+' \u0026\u0026 str !== '-' \u0026\u0026 str !== '*' \u0026\u0026 str !== '/') s.push(token); else { let b = s.pop()!; let a = s.pop()!; if (str === '+') s.push(a + b); else if (str === '-') s.push(a - b); else if (str === '*') s.push(a * b); else s.push(Math.trunc(a / b)); } } return s[0]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:59","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"224. Basic Calculator function calculate(s: string): number { return eval(s); }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:60","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"86. Partition List function partition(head: ListNode | null, x: number): ListNode | null { if (!head) return null; let nodes: ListNode[] = []; let ptr: ListNode | null = head; while (ptr) { nodes.push(ptr); ptr = ptr.next; } nodes.sort((a, b) =\u003e { if (a.val \u003c x \u0026\u0026 b.val \u003c x) return 0; else if (a.val \u003e= x \u0026\u0026 b.val \u003e= x) return 0; else if (a.val \u003e= x \u0026\u0026 b.val \u003c x) return 1; else return -1; }); let res = nodes[0]; ptr = res; for (let i = 1; i \u003c nodes.length; ++i) { ptr.next = nodes[i]!; ptr = ptr.next; } ptr.next = null; return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:61","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"105. Construct Binary Tree from Preorder and Inorder Traversal function buildTree(preorder: number[], inorder: number[]): TreeNode | null { if (preorder.length === 0) return null; let val = preorder[0]; let root = new TreeNode(val); let mid = inorder.indexOf(val); root.left = buildTree(preorder.slice(1, mid + 1), inorder.slice(0, mid)); root.right = buildTree(preorder.slice(mid + 1), inorder.slice(mid + 1)); return root; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:62","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"106. Construct Binary Tree from Inorder and Postorder Traversal function buildTree(inorder: number[], postorder: number[]): TreeNode | null { if (postorder.length === 0) return null; let val = postorder[postorder.length - 1]; let root = new TreeNode(val); let mid = inorder.indexOf(val); root.left = buildTree(inorder.slice(0, mid), postorder.slice(0, mid)); root.right = buildTree(inorder.slice(mid + 1), postorder.slice(mid, -1)); return root; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:63","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"117. Populating Next Right Pointers in Each Node II function connect(root: Node | null): Node | null { if (root === null) return root; let q: Node[] = []; q.push(root); while (q.length) { let len = q.length; for (let i = 0; i \u003c len - 1; ++i) q[i].next = q[i + 1]; for (let i = 0; i \u003c len; ++i) { let node = q.shift()!; if (node.left) q.push(node.left); if (node.right) q.push(node.right); } } return root; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:64","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"114. Flatten Binary Tree to Linked List let list: TreeNode[] = []; function dfs(root: TreeNode): void { list.push(root); if (root.left) dfs(root.left); if (root.right) dfs(root.right); } function flatten(root: TreeNode | null): void { if (!root) return; list = []; dfs(root); let len = list.length - 1; for (let i = 0; i \u003c len; ++i) { list[i].right = list[i + 1]; list[i].left = null; } list[len].right = null; list[len].left = null; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:65","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"129. Sum Root to Leaf Numbers let res: number = 0; function dfs(root: TreeNode, num: string): void { num += root.val.toString(); if (!root.left \u0026\u0026 !root.right) { res += +num; return; } if (root.left) dfs(root.left, num); if (root.right) dfs(root.right, num); } function sumNumbers(root: TreeNode | null): number { if (!root) return 0; res = 0; dfs(root, ''); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:66","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"102. Binary Tree Level Order Traversal function levelOrder(root: TreeNode | null): number[][] { let res: number[][] = []; if (!root) return res; let q: TreeNode[] = []; q.push(root); while (q.length) { let list: number[] = []; let len = q.length; while (len) { let node = q.shift()!; list.push(node.val); if (node.left) q.push(node.left); if (node.right) q.push(node.right); --len; } res.push(list); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:67","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"230. Kth Smallest Element in a BST let res: number = 0, target: number = 0, index: number = 0; function dfs(root: TreeNode): void { if (root.left) dfs(root.left); ++index; if (index === target) { res = root.val; return; } if (root.right) dfs(root.right); } function kthSmallest(root: TreeNode | null, k: number): number { if (!root) return 0; res = 0; target = k; index = 0; dfs(root); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:68","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"130. Surrounded Regions let set: Set\u003cstring\u003e = new Set(); function dfs(x: number, y: number, m: number, n: number, board: string[][]): void { set.add(`${x},${y}`); if (x + 1 \u003c= m - 1 \u0026\u0026 board[x + 1][y] === 'O' \u0026\u0026 !set.has(`${x + 1},${y}`)) dfs(x + 1, y, m, n, board); if (x - 1 \u003e= 0 \u0026\u0026 board[x - 1][y] === 'O' \u0026\u0026 !set.has(`${x - 1},${y}`)) dfs(x - 1, y, m, n, board); if (y + 1 \u003c= n - 1 \u0026\u0026 board[x][y + 1] === 'O' \u0026\u0026 !set.has(`${x},${y + 1}`)) dfs(x, y + 1, m, n, board); if (y - 1 \u003e= 0 \u0026\u0026 board[x][y - 1] === 'O' \u0026\u0026 !set.has(`${x},${y - 1}`)) dfs(x, y - 1, m, n, board); } function solve(board: string[][]): void { set.clear(); let m = board.length, n = board[0].length; for (let i = 0; i \u003c m; ++i) { if (board[i][0] === 'O') dfs(i, 0, m, n, board); if (board[i][n - 1] === 'O') dfs(i, n - 1, m, n, board); } for (let i = 0; i \u003c n; ++i) { if (board[0][i] === 'O') dfs(0, i, m, n, board); if (board[m - 1][i] === 'O') dfs(m - 1, i, m, n, board); } for (let i = 1; i \u003c m - 1; ++i) { for (let j = 1; j \u003c n - 1; ++j) { if (board[i][j] === 'O' \u0026\u0026 !set.has(`${i},${j}`)) board[i][j] = 'X'; } } }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:69","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"909. Snakes and Ladders function snakesAndLadders(board: number[][]): number { let n = board.length; let index = (x: number, y: number) =\u003e (n - 1 - x) * n + ((n - 1 - x) % 2 === 1 ? n - y : y + 1); let list: number[] = new Array(n * n + 1).fill(-1); for (let i = 0; i \u003c n; ++i) { for (let j = 0; j \u003c n; ++j) { list[index(i, j)] = board[i][j]; } } let map: Map\u003cnumber, number\u003e = new Map(); let q: number[] = []; q.push(1); map.set(1, 0); while (q.length) { let node = q.shift()!; let end = Math.min(node + 6, n * n); let step = map.get(node)!; for (let i = node + 1; i \u003c= end; ++i) { if (list[i] === -1) { if (!map.has(i) || map.get(i)! \u003e step + 1) { q.push(i); map.set(i, step + 1); } } else { if (!map.has(list[i]) || map.get(list[i])! \u003e step + 1) { q.push(list[i]); map.set(list[i], step + 1); } } } } return map.get(n * n) || -1; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:70","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"211. Design Add and Search Words Data Structure class Char { char: string; next: Char[] | null; isEnd: boolean; constructor(char: string, isEnd: boolean) { this.char = char; this.next = null; this.isEnd = isEnd; } } class WordDictionary { root: Char; constructor() { this.root = new Char('', false); } dfs(node: Char, str: string): void { let char = str[0]; let isEnd = str.length \u003e 1 ? false : true; let next: Char | null = null; if (!node.next) { node.next = []; next = new Char(char, isEnd); node.next.push(next); } else { for (let i = 0; i \u003c node.next.length; ++i) { if (node.next[i].char === char \u0026\u0026 node.next[i].isEnd === isEnd) { next = node.next[i]; break; } } if (!next) { next = new Char(char, isEnd); node.next.push(next); } } if (!isEnd) this.dfs(next, str.substring(1)); } addWord(word: string): void { this.dfs(this.root, word); } search(word: string): boolean { let index = -1; let q: Char[] = []; q.push(this.root); while (q.length) { let char = word[index + 1]; let isEnd = index === word.length - 2 ? true : false; let len = q.length; let temp = index; for (let i = 0; i \u003c len; ++i) { let node = q.shift()!; if (char != '.') { let flag = false; if (node.next) { for (let j = 0; j \u003c node.next.length; ++j) { if (node.next[j].char === char \u0026\u0026 node.next[j].isEnd === isEnd) { flag = true; q.push(node.next[j]); break; } } } if (flag) index = temp + 1; } else { if (node.next) { for (let j = 0; j \u003c node.next.length; ++j) { if (node.next[j].isEnd === isEnd) { q.push(node.next[j]); index = temp + 1; } } } } } } return index === word.length - 1 ? true : false; } } ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:71","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"46. Permutations let res: number[][] = []; let numbers: number[] = []; function dfs(list: number[]): void { if (list.length === numbers.length) { res.push([...list]); return; } for (let i = 0; i \u003c numbers.length; ++i) { if (list.includes(numbers[i]) === false) { list.push(numbers[i]); dfs(list); list.pop(); } } } function permute(nums: number[]): number[][] { res = []; numbers = nums; dfs([]); return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:72","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"148. Sort List function sortList(head: ListNode | null): ListNode | null { if (!head) return null; let ptr: ListNode | null = head; let list: ListNode[] = []; while (ptr) { list.push(ptr); ptr = ptr.next; } list.sort((a, b) =\u003e a.val - b.val); ptr = list[0]; for (let i = 0; i \u003c list.length - 1; ++i) list[i].next = list[i + 1]; list[list.length - 1].next = null; return ptr; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:73","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"74. Search a 2D Matrix function searchMatrix(matrix: number[][], target: number): boolean { let m = matrix.length, n = matrix[0].length; let up = 0, down = m, left = 0, right = n; let row = -1; while (up \u003c down) { let mid = Math.trunc((up + down) / 2); if (matrix[mid][0] === target) return true; else if (matrix[mid][0] \u003c target) { if (mid + 1 \u003e= m) { row = mid; break; } else if (matrix[mid + 1][0] \u003e= target) { if (matrix[mid + 1][0] === target) return true; row = mid; break; } else up = mid + 1; } else { if (mid - 1 \u003c 0) return false; else if (matrix[mid - 1][0] \u003c= target) { if (matrix[mid - 1][0] === target) return true; row = mid - 1; break; } else down = mid; } } if (row === -1) return false; while (left \u003c right) { let mid = Math.trunc((left + right) / 2); if (matrix[row][mid] === target) return true; else if (matrix[row][mid] \u003c target) left = mid + 1; else right = mid; } return false; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:74","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"137. Single Number II function singleNumber(nums: number[]): number { let once = 0, twice = 0; for (let i = 0; i \u003c nums.length; ++i) { once = ~twice \u0026 (once ^ nums[i]); twice = ~once \u0026 (twice ^ nums[i]); } return once; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:75","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"201. Bitwise AND of Numbers Range function rangeBitwiseAnd(left: number, right: number): number { let res = left \u0026 right; for (let i = left + 1; i \u003c right; ++i) { res \u0026= i; if (res === 0) break; } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:76","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"149. Max Points on a Line function maxPoints(points: number[][]): number { if (points.length \u003c 3) return points.length; let res = 0; let x_1 = 0, y_1 = 0, x_2 = 0, y_2 = 0; let slope = 0, b = 0; for (let i = 0; i \u003c points.length; ++i) { for (let j = i + 1; j \u003c points.length; ++j) { x_1 = points[i][0]; y_1 = points[i][1]; x_2 = points[j][0]; y_2 = points[j][1]; let cnt = 2; if (x_1 !== x_2) { slope = (y_1 - y_2) / (x_1 - x_2); b = y_1 - slope * x_1; for (let k = 0; k \u003c points.length; ++k) { if (k !== i \u0026\u0026 k !== j) { if (Math.abs(points[k][0] * slope + b - points[k][1]) \u003c 1e-9) ++cnt; } } } else { for (let k = 0; k \u003c points.length; ++k) { if (k !== i \u0026\u0026 k !== j) { if (points[k][0] === x_1) ++cnt; } } } if (cnt \u003e res) res = cnt; } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:77","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"198. House Robber function rob(nums: number[]): number { let dp: number[] = []; let len = nums.length; if (len === 1) return nums[0]; dp[0] = nums[0]; dp[1] = Math.max(dp[0], nums[1]); for (let i = 2; i \u003c len; ++i) { dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]); } return dp[len - 1]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:78","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"139. Word Break function wordBreak(s: string, wordDict: string[]): boolean { let set: Set\u003cstring\u003e = new Set(wordDict); let len = s.length; let dp: boolean[] = new Array(len + 1).fill(false); dp[0] = true; for (let i = 1; i \u003c= len; ++i) { for (let j = 0; j \u003c i; ++j) { if (dp[j]) { let word = s.substring(j, i); if (set.has(word)) dp[i] = true; } } } return dp[len]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:79","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"189. Rotate Array function rotate(nums: number[], k: number): void { let len = nums.length; k = k % len; for (let i = 0; i \u003c k; ++i) { let top = nums.pop()!; nums.splice(0, 0, top); } }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:80","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"128. Longest Consecutive Sequence function longestConsecutive(nums: number[]): number { let set: Set\u003cnumber\u003e = new Set(nums); let res = 0; let cnt = 0; for (let num of nums) { if (!set.has(num - 1)) { cnt = 1; let i = num + 1; while (set.has(i)) { ++cnt; ++i; } if (cnt \u003e res) res = cnt; } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:81","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"15. 3Sum function threeSum(nums: number[]): number[][] { let map: Map\u003cnumber, Set\u003cnumber\u003e\u003e = new Map(); let res: number[][] = []; let s_1: Set\u003cstring\u003e = new Set(), s_2: Set\u003cnumber\u003e = new Set(); let len = nums.length; for (let i = 0; i \u003c len; ++i) { let set = map.get(nums[i]); if (set === undefined) { set = new Set(); set.add(i); map.set(nums[i], set); } else set.add(i); } for (let i = 0; i \u003c len; ++i) { if (!s_2.has(nums[i])) { for (let j = i + 1; j \u003c len; ++j) { let k = 0 - nums[i] - nums[j]; let set = map.get(k); if (set !== undefined) { if (!(set.size === 0 || set.size === 1 \u0026\u0026 (set.has(i) || set.has(j)) || set.size === 2 \u0026\u0026 set.has(i) \u0026\u0026 set.has(j))) { let indexes: number[] = [nums[i], nums[j], k]; indexes.sort((a, b) =\u003e a - b); let str = indexes.toString(); if (!s_1.has(str)) { s_1.add(str); res.push(indexes); } } } } s_2.add(nums[i]); } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:82","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"236. Lowest Common Ancestor of a Binary Tree let path_1: TreeNode[] = [], path_2: TreeNode[] = []; let t_1 = 0, t_2 = 0; let f_1 = false, f_2 = false; function dfs(root: TreeNode) { if (f_1 \u0026\u0026 f_2) return; if (!f_1) path_1.push(root); if (!f_2) path_2.push(root); if (root.val === t_1) f_1 = true; if (root.val === t_2) f_2 = true; if ((!f_1 || !f_2) \u0026\u0026 root.left) dfs(root.left); if ((!f_1 || !f_2) \u0026\u0026 root.right) dfs(root.right); if (!f_1) path_1.pop(); if (!f_2) path_2.pop(); } function lowestCommonAncestor(root: TreeNode | null, p: TreeNode | null, q: TreeNode | null): TreeNode | null { if (!root || !p || !q) return null; path_1 = []; path_2 = []; t_1 = p.val; t_2 = q.val; f_1 = false; f_2 = false; let res: TreeNode | null = root; let set: Set\u003cnumber\u003e = new Set(); dfs(root); if (path_1.length \u003c path_2.length) { for (let t of path_2) set.add(t.val); for (let i = path_1.length - 1; i \u003e= 0; --i) { if (set.has(path_1[i].val)) { res = path_1[i]; break; } } } else { for (let t of path_1) set.add(t.val); for (let i = path_2.length - 1; i \u003e= 0; --i) { if (set.has(path_2[i].val)) { res = path_2[i]; break; } } } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:83","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"122. Best Time to Buy and Sell Stock II function maxProfit(prices: number[]): number { let result = 0; let sum = 0; for (let i = 1; i \u003c prices.length; ++i) { let p = prices[i] - prices[i - 1]; if (p \u003e 0) sum += p; if (sum \u003e result) result = sum; } return result; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:84","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"289. Game of Life function gameOfLife(board: number[][]): void { let row = board.length, column = board[0].length; let newBoard: number[][] = new Array(row).fill(undefined).map( () =\u003e new Array(column).fill(undefined) ); for (let i = 0; i \u003c row; ++i) { for (let j = 0; j \u003c column; ++j) { let n = 0; if (i - 1 \u003e= 0 \u0026\u0026 board[i - 1][j] === 1) ++n; if (i + 1 \u003c row \u0026\u0026 board[i + 1][j] === 1) ++n; if (j - 1 \u003e= 0 \u0026\u0026 board[i][j - 1] === 1) ++n; if (j + 1 \u003c column \u0026\u0026 board[i][j + 1] === 1) ++n; if (i - 1 \u003e= 0 \u0026\u0026 j - 1 \u003e= 0 \u0026\u0026 board[i - 1][j - 1] === 1) ++n; if (i - 1 \u003e= 0 \u0026\u0026 j + 1 \u003c column \u0026\u0026 board[i - 1][j + 1] === 1) ++n; if (i + 1 \u003c row \u0026\u0026 j - 1 \u003e= 0 \u0026\u0026 board[i + 1][j - 1] === 1) ++n; if (i + 1 \u003c row \u0026\u0026 j + 1 \u003c column \u0026\u0026 board[i + 1][j + 1] === 1) ++n; if (board[i][j] === 1) { if (n \u003c 2 || n \u003e 3) newBoard[i][j] = 0; else newBoard[i][j] = 1; } else { if (n === 3) newBoard[i][j] = 1; else newBoard[i][j] = 0; } } } for (let i = 0; i \u003c row; ++i) { for (let j = 0; j \u003c column; ++j) { board[i][j] = newBoard[i][j]; } } }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:85","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"146. LRU Cache interface LinkNode { prior: LinkNode | null; next: LinkNode | null; key: number; }; class LRUCache { map: Map\u003cnumber, number\u003e; link: Map\u003cnumber, LinkNode\u003e; first: LinkNode | null; last: LinkNode | null; capacity: number; constructor(capacity: number) { this.map = new Map(); this.link = new Map(); this.first = null; this.last = null; this.capacity = capacity; } get(key: number): number { if (this.map.has(key)) { const value = this.map.get(key)!; let newFirst: LinkNode = this.link.get(key)!; if (this.first !== newFirst) { let priorOfNewFirst = newFirst.prior!; let nextOfNewFirst = newFirst.next; priorOfNewFirst.next = nextOfNewFirst; if (nextOfNewFirst) nextOfNewFirst.prior = priorOfNewFirst; if (this.last === newFirst) this.last = newFirst.prior; newFirst.prior = null; newFirst.next = this.first; this.first!.prior = newFirst; this.first = newFirst; } return value; } else return -1; } put(key: number, value: number): void { if (this.map.has(key)) { this.map.set(key, value); let newFirst: LinkNode = this.link.get(key)!; if (this.first !== newFirst) { let priorOfNewFirst = newFirst.prior!; let nextOfNewFirst = newFirst.next; priorOfNewFirst.next = nextOfNewFirst; if (nextOfNewFirst) nextOfNewFirst.prior = priorOfNewFirst; if (this.last === newFirst) this.last = newFirst.prior; newFirst.prior = null; newFirst.next = this.first; this.first!.prior = newFirst; this.first = newFirst; } } else { if (this.map.size \u003e= this.capacity) { let newRemoved = this.last!; this.last = newRemoved.prior; if (this.last) this.last.next = null; if (this.first === newRemoved) this.first = null; this.link.delete(newRemoved.key); this.map.delete(newRemoved.key); } this.map.set(key, value); let newFirst: LinkNode = { prior: null, next: this.first, key }; if (this.first) this.first.prior = newFirst; this.first = newFirst; if (!this.last) this.last = newFirst; this.link.set(key, newFirst); } } } ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:86","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"25. Reverse Nodes in k-Group /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function reverseKGroup(head: ListNode | null, k: number): ListNode | null { if (!head || k === 1) return head; let list: ListNode[] = []; let ptr: ListNode | null = head; let result: ListNode | null = null; while (ptr) { list.push(ptr); ptr = ptr.next; } if (k \u003e list.length) return head; for (let i = k; i \u003c= list.length; i += k) { for (let j = i - 1; j \u003e i - k; --j) { list[j].next = list[j - 1]; } if (i + k \u003c= list.length) list[i - k].next = list[i + k - 1]; else if (i === list.length) list[i - k].next = null; else list[i - k].next = list[i]; } result = list[k - 1]; return result; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:87","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"25. Reverse Nodes in k-Group /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function reverseKGroup(head: ListNode | null, k: number): ListNode | null { if (!head || k === 1) return head; let ptr: ListNode | null = head; let result: ListNode | null = null; let len = 0; while (ptr) { len += 1; ptr = ptr.next; } if (k \u003e len) return head; let prior: ListNode | null = null; let tails: ListNode[] = []; ptr = head; let result: ListNode | null = null; for (let i = 0; i \u003c len; ++i) { if (i % k === 0) { if (len - i \u003e= k) tails.push(ptr); else { let tail = tails.shift(); tail.next = ptr; break; } } else if ((i + 1)% k === 0){ if (tails.length === 0) result = ptr; else { let tail = tails.shift(); tail.next = ptr; } ptr.next = prior; } else ptr.next = prior; prior = ptr; } if (tails.length) { let tail = tails.shift(); tail.next = null; } return result; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:88","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"322. Coin Change /** * @param {number[]} coins * @param {number} amount * @return {number} */ function coinChange(coins, amount) { let dp = Array(amount + 1).fill(Infinity); dp[0] = 0; for (let i = 1; i \u003c dp.length; ++i) { for (let j = 0; j \u003c coins.length; ++j) { if (i - coins[j] \u003e= 0) dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1); } } return dp[amount] === Infinity ? -1 : dp[amount]; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:89","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"300. Longest Increasing Subsequence /** * @param {number[]} nums * @return {number} */ var lengthOfLIS = function (nums) { if (nums.length === 1) return 1; let dp = Array(nums.length).fill(1); dp[dp.length - 1] = 1; let res = 0; for (let i = dp.length - 2; i \u003e= 0; --i) { let max = 0; for (let j = i + 1; j \u003c dp.length; ++j) { if (nums[j] \u003e nums[i]) { if (dp[j] + 1 \u003e max) max = dp[j] + 1; } } dp[i] = Math.max(max, dp[i]); res = Math.max(res, dp[i]); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:90","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"120. Triangle /** * @param {number[][]} triangle * @return {number} */ var minimumTotal = function (triangle) { let dp = []; for (let i = 0; i \u003c triangle.length; ++i) { dp.push(Array(triangle[i].length).fill(Infinity)); } dp[0][0] = triangle[0][0]; for (let i = 1; i \u003c triangle.length; ++i) { for (let j = 0; j \u003c triangle[i].length; ++j) { if (j === triangle[i].length - 1) dp[i][j] = dp[i - 1][j - 1] + triangle[i][j]; else if (j === 0) dp[i][j] = dp[i - 1][j] + triangle[i][j]; else dp[i][j] = Math.min(dp[i - 1][j - 1], dp[i - 1][j]) + triangle[i][j]; } } let res = Infinity; for (let i = 0; i \u003c dp[dp.length - 1].length; ++i) { res = Math.min(res, dp[dp.length - 1][i]); } return res; }; ","date":"2024-04-19","objectID":"/recent-leetcode-top-interview-150-problem-solving-record/:0:91","tags":["LeetCode","TypeScript","JavaScript","data structure","algorithm"],"title":"Recent LeetCode Top Interview 150 Problem-Solving Record","uri":"/recent-leetcode-top-interview-150-problem-solving-record/"},{"categories":["Note"],"content":"I recently found Coze by ByteDance, which allows free access to GPT-4 and GPT-4-Turbo! Coze https://www.coze.com/ You can refer to the official documentation for specific usage methods. It supports customizing your own bot through plugins, knowledge bases, etc. In short, it’s very powerful, and you can also publish the bot to platforms such as Discord, Slack, Telegram, etc. More importantly, I found a project on Github: coze-discord-proxy. By handling Discord, you can proxy the Coze bot published on Discord to an OpenAI-formatted API, so you can use GPT-4 anywhere. It seems that I can save money for ChatGPT Plus! ","date":"2024-03-02","objectID":"/coze-free-access-to-gpt-4/:0:0","tags":["ChatGPT","Github"],"title":"Coze: Free Access to GPT-4","uri":"/coze-free-access-to-gpt-4/"},{"categories":["Project"],"content":" Node-Depend-View https://github.com/kayak4665664/Node-Depend-View I completed this small project while learning frontend and Node.js development. It can display the dependency relationship of a project in graphical form. I also published it to npm. Please see the link above for details. I feel that it is very interesting to do full-stack development with TypeScript, and I hope to find an internship in the new year! Okay, I won’t say much, come on! 💪 ","date":"2024-01-04","objectID":"/node-depend-view/:0:0","tags":["TypeScript","Node.js","command line tools","Frontend","Full Stack","algorithms","Github"],"title":"Node-Depend-View","uri":"/node-depend-view/"},{"categories":["Note"],"content":"LeetCode Linked List ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:0","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"707. Design Linked List class MyLinkedList { val: number | undefined; next: MyLinkedList | undefined; prior: MyLinkedList | undefined; constructor () { this.val = undefined; this.next = undefined; this.prior = undefined; } get ( index: number ): number { if ( index == 0 ) return this.val != undefined ? this.val : -1; else if ( !this.next ) return -1; else { let ptr = this.next, i = 1; while ( i \u003c index \u0026\u0026 ptr.next ) { ptr = ptr.next; ++i; } if ( i == index ) return ptr.val != undefined ? ptr.val : -1; else return -1; } } addAtHead ( val: number ): void { if ( this.val == undefined ) this.val = val; else { const next = new MyLinkedList(); next.val = this.val; next.next = this.next; if ( next.next ) next.next.prior = next; next.prior = this; this.val = val; this.next = next; this.prior = undefined; } } addAtTail ( val: number ): void { if ( this.val == undefined ) this.val = val; else { const tail = new MyLinkedList(); tail.val = val; let ptr = this.next; if ( !ptr ) { this.next = tail; tail.prior = this; } else { while ( ptr.next ) ptr = ptr.next; ptr.next = tail; tail.prior = ptr; } } } addAtIndex ( index: number, val: number ): void { if ( index == 0 ) this.addAtHead( val ); else { if ( !this.next ) { if ( index == 1 \u0026\u0026 this.val != undefined ) this.addAtTail( val ); else return; } else { let i = 1, ptr = this.next; while ( i \u003c index \u0026\u0026 ptr.next ) { ++i; ptr = ptr.next; } if ( i == index ) { const prior = new MyLinkedList(); prior.val = val; if ( ptr.prior ) { ptr.prior.next = prior; prior.prior = ptr.prior; } prior.next = ptr; ptr.prior = prior; } else if ( i + 1 == index ) { const tail = new MyLinkedList(); tail.val = val; ptr.next = tail; tail.prior = ptr; } } } } deleteAtIndex ( index: number ): void { if ( index == 0 ) { if ( this.next ) { this.val = this.next.val; this.next = this.next.next; if ( this.next ) this.next.prior = this; } else this.val = undefined; } else if ( !this.next ) return; else { let i = 1, ptr = this.next; while ( i \u003c index \u0026\u0026 ptr.next ) { ++i; ptr = ptr.next; } if ( i == index \u0026\u0026 ptr.prior ) { if ( ptr.next ) { ptr.prior.next = ptr.next; ptr.next.prior = ptr.prior; } else ptr.prior.next = undefined; } } } } /** * Your MyLinkedList object will be instantiated and called as such: * var obj = new MyLinkedList() * var param_1 = obj.get(index) * obj.addAtHead(val) * obj.addAtTail(val) * obj.addAtIndex(index,val) * obj.deleteAtIndex(index) */ ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:1","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"141. Linked List Cycle /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function hasCycle ( head: ListNode | null ): boolean { const m: Map\u003cListNode, boolean\u003e = new Map(); let ptr = head, res = false; while ( ptr !== null ) { if ( !m.has( ptr ) ) { m.set( ptr, true ); ptr = ptr.next; } else { res = true; break; } } return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:2","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"142. Linked List Cycle II /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function detectCycle ( head: ListNode | null ): ListNode | null { const m: Map\u003cListNode, boolean\u003e = new Map(); let ptr = head, res: ListNode | null = null; while ( ptr !== null ) { if ( !m.has( ptr ) ) { m.set( ptr, true ); ptr = ptr.next; } else { res = ptr; break; } } return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:3","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"160. Intersection of Two Linked Lists /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function getIntersectionNode ( headA: ListNode | null, headB: ListNode | null ): ListNode | null { let m: Map\u003cListNode, boolean\u003e = new Map(), ptrA = headA, ptrB = headB, res: ListNode | null = null; while ( ptrA !== null ) { m.set( ptrA, true ); ptrA = ptrA.next; } while ( ptrB !== null ) { if ( !m.has( ptrB ) ) { m.set( ptrB, true ); ptrB = ptrB.next; } else { res = ptrB; break; } } return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:4","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"19. Remove Nth Node From End of List /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function removeNthFromEnd ( head: ListNode | null, n: number ): ListNode | null { let ptr = head, res: ListNode | null, list: ListNode[] = []; while ( ptr !== null ) { list.push( ptr ); ptr = ptr.next; } let len = list.length; if ( n == len \u0026\u0026 head ) res = head.next; else { let prior = list[ len - n - 1 ], next = n == 1 ? null : list[ len - n + 1 ]; prior.next = next; res = head; } return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:5","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"206. Reverse Linked List /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function reverseList ( head: ListNode | null ): ListNode | null { let res: ListNode | null = null, list: ListNode[] = [], ptr = head; while ( ptr !== null ) { list.push( ptr ); ptr = ptr.next; } let len = list.length; res = list[ len - 1 ] === undefined ? null : list[ len - 1 ]; for ( let i = len - 1; i \u003e 0; --i ) { let prior = list[ i - 1 ], node = list[ i ]; node.next = prior; } if ( len \u003e 0 ) list[ 0 ].next = null; return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:6","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"203. Remove Linked List Elements /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function removeElements ( head: ListNode | null, val: number ): ListNode | null { let res: ListNode | null = null, list: ListNode[] = [], ptr = head; while ( ptr !== null ) { if ( ptr.val != val ) list.push( ptr ); ptr = ptr.next; } let len = list.length; if ( len \u003e 0 ) res = list[ 0 ]; for ( let i = 0; i \u003c len - 1; ++i ) list[ i ].next = list[ i + 1 ]; if ( len \u003e 0 ) list[ len - 1 ].next = null; return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:7","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"328. Odd Even Linked List /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function oddEvenList ( head: ListNode | null ): ListNode | null { let odd = head, ptr = head, oddTail: ListNode | null = head, even: ListNode | null = null, i = 1, evenTail: ListNode | null = null; while ( ptr !== null ) { if ( i % 2 != 0 ) { if ( i \u003e 1 \u0026\u0026 oddTail ) { oddTail.next = ptr; oddTail = ptr; } } else { if ( i == 2 ) { even = ptr; evenTail = ptr; } else { if ( evenTail ) { evenTail.next = ptr; evenTail = ptr; } } } ptr = ptr.next; ++i; } if ( oddTail ) oddTail.next = even; if ( evenTail ) evenTail.next = null; return odd; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:8","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"234. Palindrome Linked List /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function isPalindrome ( head: ListNode | null ): boolean { let list: number[] = [], ptr = head, res = true; while ( ptr !== null ) { list.push( ptr.val ); ptr = ptr.next; } let left = 0, right = list.length - 1; while (left \u003c= right) { if (list[right] != list[left]) { res = false; break; } ++left; --right; } return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:9","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"21. Merge Two Sorted Lists /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { if (list1 == nullptr \u0026\u0026 list2 == nullptr) return nullptr; else if (list1 == nullptr) return list2; else if (list2 == nullptr) return list1; else { ListNode *front, *p, *p1, *p2; if (list1-\u003eval \u003c= list2-\u003eval) { front = list1; p1 = list1-\u003enext; p2 = list2; } else { front = list2; p1 = list1; p2 = list2-\u003enext; } p = front; while (p1 != nullptr \u0026\u0026 p2 != nullptr) { if (p1-\u003eval \u003c= p2-\u003eval) { p-\u003enext = p1; p1 = p1-\u003enext; } else { p-\u003enext = p2; p2 = p2-\u003enext; } p = p-\u003enext; } if (p1 == nullptr) p-\u003enext = p2; else p-\u003enext = p1; return front; } } }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:10","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"2. Add Two Numbers /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function addTwoNumbers ( l1: ListNode | null, l2: ListNode | null ): ListNode | null { let ptr1 = l1, ptr2 = l2; while ( ptr2 !== null || ptr1 !== null ) { if ( ptr2 !== null \u0026\u0026 ptr1 !== null ) { ptr1.val += ptr2.val; if ( ptr1.val \u003e 9 ) { if ( ptr1.next ) { ptr1.next.val += 1; ptr1.val -= 10; } else { let next = new ListNode( 1 ); ptr1.val -= 10; ptr1.next = next; } } if ( ptr2.next \u0026\u0026 ptr1.next === null ) ptr1.next = new ListNode( 0 ); ptr1 = ptr1.next; ptr2 = ptr2.next; } else if ( ptr2 === null \u0026\u0026 ptr1 ) { if ( ptr1.val \u003e 9 ) { if ( ptr1.next ) { ptr1.next.val += 1; ptr1.val -= 10; if ( ptr1.next.val \u003c 10 ) break; ptr1 = ptr1.next; } else { let next = new ListNode( 1 ); ptr1.val -= 10; ptr1.next = next; } } else break; } } return l1; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:11","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"430. Flatten a Multilevel Doubly Linked List /** * Definition for node. * class Node { * val: number * prev: Node | null * next: Node | null * child: Node | null * constructor(val?: number, prev? : Node, next? : Node, child? : Node) { * this.val = (val===undefined ? 0 : val); * this.prev = (prev===undefined ? null : prev); * this.next = (next===undefined ? null : next); * this.child = (child===undefined ? null : child); * } * } */ function flatten ( head: Node | null ): Node | null { let ptr = head; while ( ptr !== null ) { if ( ptr.child ) { let next = ptr.next; let child = flatten( ptr.child ); ptr.child = null; if ( child ) { ptr.next = child; child.prev = ptr; while ( ptr.next ) ptr = ptr.next; ptr.next = next; if ( next ) next.prev = ptr; } } ptr = ptr.next; } return head; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:12","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"138. Copy List with Random Pointer /** * Definition for Node. * class Node { * val: number * next: Node | null * random: Node | null * constructor(val?: number, next?: Node, random?: Node) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * this.random = (random===undefined ? null : random) * } * } */ function copyRandomList ( head: Node | null ): Node | null { let res: Node | null = null, list: Node[] = [], map: Map\u003cNode, number\u003e = new Map(), ptr = head, i = 0; while ( ptr !== null ) { let node = new Node( ptr.val ); list.push( node ); map.set( ptr, i ); ++i; ptr = ptr.next; } ptr = head; i = 0; while ( ptr !== null ) { if ( list[ i ] ) { list[ i + 1 ] ? list[ i ].next = list[ i + 1 ] : null; if ( ptr.random ) { let index = map.get( ptr.random ); index !== undefined ? list[ i ].random = list[ index ] : null; } else list[ i ].random = null; } ++i; ptr = ptr.next; } res = list[ 0 ]; return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:13","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"61. Rotate List /** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ function rotateRight ( head: ListNode | null, k: number ): ListNode | null { if ( k == 0 ) return head; let map: Map\u003cnumber, ListNode\u003e = new Map(), ptr = head, i = 0, res: ListNode | null = null; while ( ptr ) { map.set( i, ptr ); ptr = ptr.next; ++i; } if ( i \u003c 2 || k % i == 0 ) return head; k = i - k % i; if ( k == 0 ) res = head; else { let node = map.get( k ); node ? res = node : res = null; if ( res ) { ptr = res; while ( ptr.next ) ptr = ptr.next; ptr.next = head; ptr = head; while ( ptr \u0026\u0026 ptr.next !== res ) ptr = ptr.next; if ( ptr ) ptr.next = null; } } return res; }; ","date":"2023-10-18","objectID":"/leetcode-linked-list-solutions/:0:14","tags":["LeetCode","TypeScript","C++","linked list","data structure","algorithms"],"title":"Leetcode Linked List Solutions","uri":"/leetcode-linked-list-solutions/"},{"categories":["Note"],"content":"I need to simulate location on iPhone recently. After some research, I finally found a simple and effective method. I found several methods online, without jailbreaking iPhone. The first one is to use AnyGo, which is effective but requires payment. The second one is to use an Android phone with root permission, install OTGLocation, and then connect the iPhone to this Android phone. Other methods include using Xcode, i4Tools, or external devices, or even simulating satellite signals to deceive the iPhone. I think these methods are too complicated. I found a simple and effective method at https://shawnhuangyh.com/post/ios-17-location-simulation/, which mainly uses pymobiledevice3. ","date":"2023-10-13","objectID":"/simulate-locations-for-ios17/:0:0","tags":["iPhone","macOS","Python","command line tools"],"title":"Simulate Locations for iOS17","uri":"/simulate-locations-for-ios17/"},{"categories":["Note"],"content":"1. Install pymobiledevice3 on macOS: python3 -m pip install -U pymobiledevice3 ","date":"2023-10-13","objectID":"/simulate-locations-for-ios17/:0:1","tags":["iPhone","macOS","Python","command line tools"],"title":"Simulate Locations for iOS17","uri":"/simulate-locations-for-ios17/"},{"categories":["Note"],"content":"2. Enable developer mode on iPhone, located at Settings -\u003e Privacy \u0026 Security -\u003e Developer Mode. ","date":"2023-10-13","objectID":"/simulate-locations-for-ios17/:0:2","tags":["iPhone","macOS","Python","command line tools"],"title":"Simulate Locations for iOS17","uri":"/simulate-locations-for-ios17/"},{"categories":["Note"],"content":"3. Connect the iPhone to macOS, and execute: sudo python3 -m pymobiledevice3 remote start-tunnel It will print something like the following: Interface: utun6 RSD Address: fd7b:e5b:6f53::1 RSD Port: 64337 Use the follow connection option: --rsd fd7b:e5b:6f53::1 64337 RSD Address and RSD Port will be used in step 5. ","date":"2023-10-13","objectID":"/simulate-locations-for-ios17/:0:3","tags":["iPhone","macOS","Python","command line tools"],"title":"Simulate Locations for iOS17","uri":"/simulate-locations-for-ios17/"},{"categories":["Note"],"content":"4. Make sure the iPhone is not locked at this time, and execute on macOS: sudo pymobiledevice3 mounter auto-mount ","date":"2023-10-13","objectID":"/simulate-locations-for-ios17/:0:4","tags":["iPhone","macOS","Python","command line tools"],"title":"Simulate Locations for iOS17","uri":"/simulate-locations-for-ios17/"},{"categories":["Note"],"content":"5. Continue to execute on macOS: pymobiledevice3 developer dvt simulate-location set --rsd \u003cRSD Address\u003e \u003cRSD Port\u003e -- \u003clatitude\u003e \u003clongtitude\u003e Replace \u003cRSD Address\u003e and \u003cRSD Port\u003e with the values printed in step 3, and replace \u003clatitude\u003e and \u003clongtitude\u003e with the latitude and longitude you want to simulate. Look at the iPhone, the location has been simulated successfully. After terminating the simulation, the iPhone will return to the real location. ","date":"2023-10-13","objectID":"/simulate-locations-for-ios17/:0:5","tags":["iPhone","macOS","Python","command line tools"],"title":"Simulate Locations for iOS17","uri":"/simulate-locations-for-ios17/"},{"categories":["Note"],"content":"Leetcode Arrays 101 ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:0","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"485. Max Consecutive Ones const findMaxConsecutiveOnes = (nums: number[]): number =\u003e { let res = 0, len = 0, end = nums.length; for (let i = 0; i \u003c end; ++i) { if (nums[i] == 1) ++len; else { res = Math.max(res, len); len = 0; } } res = Math.max(res, len); return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:1","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"1295. Find Numbers with Even Number of Digits const findMaxConsecutiveOnes = (nums: number[]): number =\u003e { let res = 0, len = 0, end = nums.length; for (let i = 0; i \u003c end; ++i) { if (nums[i] == 1) ++len; else { res = Math.max(res, len); len = 0; } } res = Math.max(res, len); return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:2","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"977. Squares of a Sorted Array function sortedSquares(nums: number[]): number[] { nums = nums.map(num =\u003e num * num); nums.sort((a, b) =\u003e a - b); return nums; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:3","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"1089. Duplicate Zeros /** Do not return anything, modify arr in-place instead. */ function duplicateZeros ( arr: number[] ): void { let i = 0, len = arr.length; while ( i \u003c len ) { if ( arr[ i ] != 0 ) ++i; else { arr.splice( i, 0, 0 ); arr.pop(); i += 2; } } }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:4","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"88. Merge Sorted Array /** Do not return anything, modify nums1 in-place instead. */ function merge ( nums1: number[], m: number, nums2: number[], n: number ): void { let i = 0, end = m; for ( let num of nums2 ) { while ( i \u003c end \u0026\u0026 nums1[ i ] \u003c num ) ++i; nums1.splice( i, 0, num ); nums1.pop(); ++end; } }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:5","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"27. Remove Element function removeElement ( nums: number[], val: number ): number { let res = 0, i = 0; while ( i \u003c nums.length ) { if ( nums[ i ] != val ) { ++res; ++i; } else nums.splice( i, 1 ); } return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:6","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"26. Remove Duplicates from Sorted Array function removeDuplicates(nums: number[]): number { const set: Set\u003cnumber\u003e = new Set(); let i = 0; while (i \u003c nums.length) { if (set.has(nums[i])) nums.splice(i, 1); else { set.add(nums[i]); ++i; } } return nums.length; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:7","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"1346. Check If N and Its Double Exist function checkIfExist(arr: number[]): boolean { let res = false; const set: Set\u003cnumber\u003e = new Set(arr); const zeros = arr.filter(num =\u003e num == 0); const len = zeros.length; for (let s of set) { if (set.has(2 * s)) { if (s == 0 \u0026\u0026 len \u003c 2) continue; res = true; break; } } return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:8","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"941. Valid Mountain Array function validMountainArray(arr: number[]): boolean { let res = true, inc = true, len = arr.length; if (len \u003c 3 || arr[0] \u003e= arr[1] ) return false; for (let i = 0; i \u003c len; ++i) { if (inc \u0026\u0026 (arr[i] \u003c arr[i - 1])) inc = false; if (arr[i] == arr[i - 1] || (!inc \u0026\u0026 (arr[i] \u003e= arr[i - 1]))) { res = false; break; } } if (inc) res = false; return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:9","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"1299. Replace Elements with Greatest Element on Right Side function replaceElements(arr: number[]): number[] { let res: number[] = [], len = arr.length; for (let i = 0; i \u003c len - 1; ++i) { let max = Math.max(...arr.slice(i + 1, len)); res.push(max); } res.push(-1); return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:10","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"26. Remove Duplicates from Sorted Array function removeDuplicates(nums: number[]): number { const set: Set\u003cnumber\u003e = new Set(); let i = 0; while (i \u003c nums.length) { if (set.has(nums[i])) nums.splice(i, 1); else { set.add(nums[i]); ++i; } } return nums.length; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:11","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"283. Move Zeroes /** Do not return anything, modify nums in-place instead. */ function moveZeroes ( nums: number[] ): void { let i = 0, j = 1, len = nums.length; while ( i \u003c len \u0026\u0026 j \u003c len ) { if ( nums[ i ] == 0 \u0026\u0026 nums[ j ] != 0 ) { let temp = nums[ i ]; nums[ i ] = nums[ j ]; nums[ j ] = temp; } if ( nums[ i ] != 0 ) ++i; if ( j \u003c i ) j = i; else if ( nums[ j ] == 0 ) ++j } }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:12","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"905. Sort Array By Parity function sortArrayByParity(nums: number[]): number[] { let res: number[] = []; res = nums.sort((a, b) =\u003e { if (a % 2 == 0 \u0026\u0026 b % 2 != 0) return -1; else if (a % 2 != 0 \u0026\u0026 b % 2 == 0) return 1; else return 0; }); return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:13","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"27. Remove Element function removeElement ( nums: number[], val: number ): number { let res = 0, i = 0; while ( i \u003c nums.length ) { if ( nums[ i ] != val ) { ++res; ++i; } else nums.splice( i, 1 ); } return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:14","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"1051. Height Checker function heightChecker(heights: number[]): number { let res = 0, len = heights.length; const temp = [...heights]; heights.sort((a, b) =\u003e a - b); for (let i = 0; i \u003c len; ++i) { if (temp[i] != heights[i]) ++res; } return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:15","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"414. Third Maximum Number function thirdMax ( nums: number[] ): number { let a = -Infinity, b = -Infinity, c = -Infinity; for ( let n of nums ) { if ( n \u003e a || n \u003e b \u0026\u0026 n \u003c a || n \u003e c \u0026\u0026 n \u003c b ) c = n; if ( c \u003e b ) { let t = c; c = b; b = t; } if ( b \u003e a ) { let t = b; b = a; a = t; } } if ( c != -Infinity ) return c; else return a; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:16","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"448. Find All Numbers Disappeared in an Array function findDisappearedNumbers(nums: number[]): number[] { const len = nums.length, s: Set\u003cnumber\u003e = new Set(nums), res: number[] = []; for (let i = 1; i \u003c= len; ++i) { if (!s.has(i)) res.push(i); } return res; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:17","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Note"],"content":"977. Squares of a Sorted Array function sortedSquares(nums: number[]): number[] { nums = nums.map(num =\u003e num * num); nums.sort((a, b) =\u003e a - b); return nums; }; ","date":"2023-10-10","objectID":"/leetcode-arrays-101-solutions/:0:18","tags":["LeetCode","array","data structure","algorithms","TypeScript"],"title":"Leetcode Arrays 101 Solutions","uri":"/leetcode-arrays-101-solutions/"},{"categories":["Journal"],"content":" Hope I can reach 50 hours next week🌲 ","date":"2023-10-01","objectID":"/focus-statistics-40-2023/:0:0","tags":["focus statistics"],"title":"Focus Statistics (Week 40, 2023)","uri":"/focus-statistics-40-2023/"},{"categories":["Note"],"content":"Today I found a command line tool that can limit the battery charging of Apple Silicon Macbook, called battery. battery https://github.com/actuallymentor/battery I have been using AlDente before. Compared with it, the advantage of battery is that it can be used directly on the command line, and it is completely free, while AlDente can only use the most basic functions without paying, and its icon occupies a spot in the menu bar. Just one line of command: curl -s https://raw.githubusercontent.com/actuallymentor/battery/main/setup.sh | bash After the installation is complete, you can use battery help to view help information, it’s so easy. ","date":"2023-09-23","objectID":"/battery-battery-charge-limiter-for-apple-silicon-macbook-devices/:0:0","tags":["macOS","command line tools"],"title":"battery: Battery Charge Limiter for Apple Silicon Macbook Devices","uri":"/battery-battery-charge-limiter-for-apple-silicon-macbook-devices/"},{"categories":["Project"],"content":"I suddenly found that the font family in Chrome Devtools cannot be modified directly the day before yesterday. I checked it and found that I can write an extension to solve this problem. Devtools-Font https://github.com/kayak4665664/Devtools-Font I mainly refer to https://gist.github.com/vbsessa/e337d0add70a71861b8c580d5e16996e, but the font in “Sources” does not change according to this tutorial. I made some modifications based on this. Finally, I changed the font to FiraCode Nerd Font. I have to say that this font is really good-looking, and there is a ligature effect. ","date":"2023-08-26","objectID":"/devtools-font/:0:0","tags":["Browser","Chrome Extension","Frontend"],"title":"Devtools-Font","uri":"/devtools-font/"},{"categories":["Journal"],"content":"We moved from Yanqi Lake Campus to the city of Beijing on July 12. Here are some photos I took in the last few days at Yanqi Lake Campus. Rainbow Two donkeys Crow Bee Colorful lights on the mountain Street light Duck Bird on the wire Goldfish Cormorant Cormorant Cormorant Fog on the mountain after rain ","date":"2023-07-16","objectID":"/last-days-at-yanqi-lake-campus/:0:0","tags":["UCAS","stroll"],"title":"Last Days at Yanqi Lake Campus","uri":"/last-days-at-yanqi-lake-campus/"},{"categories":["Note"],"content":"I encountered a problem when I was completing Springboot-Demo, which is to get resource files. At first, I packaged the project into a jar file using Maven, and then ran it. The program reported an error that it could not find the json file. After troubleshooting, I found that the problem was in the way I got the json file. I used a relative path, but when running the jar file, the relative path is relative to the directory where the jar file is located, not relative to the source code directory, so the json file cannot be found. The solution is to use the getResourceAsStream method of the ClassLoader class, which can return an InputStream object according to the given path name, and then use this object to read the contents of the resource file. For example: //Assuming there is a Main class, get the class loader object ClassLoader classLoader = Main.class.getClassLoader(); //Get the input stream object according to the resource file name InputStream inputStream = classLoader.getResourceAsStream(\"test.log\"); ","date":"2023-06-11","objectID":"/get-resource-files-through-classloader/:0:0","tags":["Java"],"title":"Get Resource Files Through ClassLoader","uri":"/get-resource-files-through-classloader/"},{"categories":["Project"],"content":"I chose a Java programming course this semester, and finally completed a project, which is Springboot-Demo. Springboot-Demo https://github.com/kayak4665664/Springboot-Demo The function of this program is to read data from the json file and then display it on the page. In addition to the Springboot framework, the front end is still my commonly used Layui and Highcharts. I chose this Java course mainly to practice Java’s Web development. I remember when I was a junior, there was a software engineering practice course, and one of the experiments was to make a Web application. At that time, I first came into contact with Web development. I wanted to use Java and Springboot to complete it. I found some tutorials on the Internet and felt a little unclear. Then I learned about the Django framework of python, and found it easier to understand. Finally, I used Django to do that experiment. This time I used Springboot, and I feel that it is not much different from Django. ","date":"2023-06-11","objectID":"/springboot-demo/:0:0","tags":["Java"],"title":"Springboot-Demo","uri":"/springboot-demo/"},{"categories":["Journal"],"content":"My current glasses were bought before I went to college, and I can’t see clearly anymore. I am in Beijing, and I heard that Panjiayuan (Beijing Glasses City) had very cheap glasses, so I went there. I saw photochromic glasses somewhere before, which can change color according to the intensity of ultraviolet rays. I decided to get a pair of photochromic glasses this time. I checked on the Internet, everyone said that Zeiss and Essilor lenses are better, I compared them, and finally decided to buy a pair of Zeiss PhotoFusion X lenses. My degree should be within 800 degrees, so I can choose a lens with a refractive index of 1.6. I saw a strategy saying that it is cheaper to get glasses online. Go to the optometry first, then go to the physical store to try on the frame, write down the frame model, then buy the frame online, and then send the frame and optometry to the merchant who sells the lens, and the merchant mails it later after processing. I think this method has too many links, and I especially don’t like to wait for express delivery, so I decided to go to Panjiayuan to have a look. It is said on the Internet that the water in Panjiayuan is very deep. I saw a lot of strategies on Zhihu and Xiaohongshu, and I was confused. Later, I felt that most of these were soft advertisements, so I might as well not read them. I think as long as the price is not higher than the online price, the lens is not fake, and the frame is suitable, it will be fine. Another point is that everyone said not to have optometry in Panjiayuan’s shop, the result is not very accurate. It is best to go to Beijing Tongren Optometry Center, but you need to make an appointment in advance. When I made an appointment, it was already full. I made an appointment to go to Baodao Optical for optometry. Baodao Optical is a national chain and is relatively professional. The Yanqi Lake Campus of UCAS is too far away from downtown Beijing. Fortunately, the school has a daily shuttle bus. Saturday is relatively free, I booked the shuttle bus for 7 am on Saturday. It was the first time I took a shuttle bus to the city. I didn’t expect so many people to enter the city on Saturday. When I arrived at the station, the bus was already full, and when I got on the second bus, there were only four or five seats left. It took less than an hour to get to the drop-off point at the Olympic Village, and it was the first time I entered the city since school started in February. I immediately got on the subway again and went to Baodao Optical for optometry first. After getting off the subway and walking slowly, it was exactly 9 o’clock, and there was no customer in the store. Register a member for free, and the “exquisite optometry” service can be discounted by 10 yuan to 50 yuan. Afterward, optometry began, and about 3 kinds of instruments were used, which took more than ten minutes. The optometrist told me that the result is that the left and right eyes are more than 600 degrees, and both have about 100 degrees of astigmatism. Fortunately, it’s about the same as before I went to college. I tried it on with glasses, and it felt good. The optometry results of Baodao Glasses can be checked directly in the WeChat public account, which is very convenient. The optometrist also said that if you often see close-ups, it is best not to wear glasses corrected to 1.0. 0.8 and 0.9 are fine. According to the results of my optometry, I do need a pair of photochromic glasses. After coming out of Baodao Glasses, I went straight to the bus station and rushed to Panjiayuan. It was about 10 o’clock when I arrived at the station. As said on the Internet, many people solicited customers when I got off the bus. On the overpass, the opposite is Beijing Glasses City. As soon as I entered the gate, there were all optical shops. It was said on the Internet that the higher the floor, the cheaper the optical shops, so I went upstairs directly. I turned around on the third and fourth floors, not knowing whose sh","date":"2023-04-26","objectID":"/go-to-panjiayuan-to-get-glasses/:0:0","tags":["stroll"],"title":"Go to Panjiayuan to Get Glasses","uri":"/go-to-panjiayuan-to-get-glasses/"},{"categories":["Project"],"content":"Previous article introduces how to capture packets, and this article introduces how to write a program to parse the captured packet files. Info The source code involved in this article is in the GitHub repository: Pcap-Parser https://github.com/kayak4665664/Pcap-Parser The Pcap file contains the information of the network data packet, including source IP address, destination IP address, source port, destination port, transport layer protocol, application layer protocol, etc. Therefore, the idea of the program is to parse from the data link layer to the application layer and parse out the protocol type and protocol data of each layer. In terms of implementation, you can refer to the analysis results of Wireshark. For C/C++, \u003cpcap.h\u003e can be used to process Pcap files. Afterward, use \u003cnet/ethernet.h\u003e, \u003cnetinet/ip.h\u003e, \u003cnetinet/tcp.h\u003e defined the Ethernet header, IP header, and TCP header structure to parse the data Link layer, network layer, and transport layer. In addition, both the IP header and the TCP header have options, which is not in the structure. There are many types of protocols in the application layer, and programs need to be written for each protocol. My program supports parsing HTTP and TLS protocols. HTTP is a plain text protocol, and the data fields are separated by \\r\\n. In addition, it is necessary to consider that an HTTP message is divided into several packets, and the correct result can only be parsed after reassembling the relevant packets. And TLS is an encryption protocol, which is more complicated. It needs to be parsed according to the structure of the protocol, and reassembling should also be considered. The above are just some simple ideas. There are many complicated situations that have not been covered. ","date":"2023-04-11","objectID":"/pcap-parser/:0:0","tags":["C++","Github","algorithms","packet capture","command line tools"],"title":"Pcap-Parser","uri":"/pcap-parser/"},{"categories":["Note"],"content":"Packet capture for mobile apps using Charles, Wireshark and tcpdump. Info I capture packets for iPhone on macOS, but the methods and principles are similar for other systems and devices. ","date":"2023-04-10","objectID":"/capture-packets-for-mobile-apps/:0:0","tags":["packet capture","iPhone","macOS","command line tools"],"title":"Capture Packets for Mobile Apps","uri":"/capture-packets-for-mobile-apps/"},{"categories":["Note"],"content":"Wireshark Wireshark is an open-source network analysis tool that can be used to capture network packets. It can run on macOS, Windows, and Linux. On macOS, Wireshark can be installed using brew: brew install --cask wireshark Capturing packets with Wireshark is also very simple. For example, selecting the Wi-Fi interface can capture packets from the wireless network card. ","date":"2023-04-10","objectID":"/capture-packets-for-mobile-apps/:1:0","tags":["packet capture","iPhone","macOS","command line tools"],"title":"Capture Packets for Mobile Apps","uri":"/capture-packets-for-mobile-apps/"},{"categories":["Note"],"content":"tcpdump tcpdump is a command line tool that can be used to capture network packets. For example, if you want to capture packets on a server without a graphical interface, you can use it. On macOS, tcpdump can also be installed using brew: brew install tcpdump Capturing packets with tcpdump, for example, capture packets from the 12345 port and save them as a pcap file: tcpdump port 12345 -w capture.pcap ","date":"2023-04-10","objectID":"/capture-packets-for-mobile-apps/:2:0","tags":["packet capture","iPhone","macOS","command line tools"],"title":"Capture Packets for Mobile Apps","uri":"/capture-packets-for-mobile-apps/"},{"categories":["Note"],"content":"Charles Charles is an HTTP proxy and monitor that can be used to capture HTTP and HTTPS packets. It’s like Fiddler on Windows. On macOS, we can install Charles using brew: brew install --cask charles ","date":"2023-04-10","objectID":"/capture-packets-for-mobile-apps/:3:0","tags":["packet capture","iPhone","macOS","command line tools"],"title":"Capture Packets for Mobile Apps","uri":"/capture-packets-for-mobile-apps/"},{"categories":["Note"],"content":"Capture Packets for Mobile Apps For MacBook, if Wi-Fi is already connected, the wireless hotspot cannot be turned on. So you need to use Charles to set up a proxy server, and then the phone connects to the proxy server. The main steps are as follows: Both the macOS device and the iPhone are connected to a mobile hotspot turned on by the third device, making sure they are on the same local area network. On the macOS device, open Charles and set up a proxy server. The proxy server port is 8888 by default. On the iPhone, set the proxy server to the macOS device. The proxy server port is 8888. Access chls.pro/ssl in the iPhone browser, download and install the certificate. Trust the certificate in the iPhone settings General -\u003e About -\u003e Certificate Trust Settings. Install the configuration file for the proxy server in the iPhone settings General -\u003e VPN \u0026 Device Management. Since Charles can only capture HTTP and HTTPS packets, start Wireshark on the macOS device and select the Wi-Fi interface to capture packets of all protocols. Open the mobile app on the iPhone and use it. Stop capturing packets in Wireshark. The previously set proxy server port is 8888, so you can filter irrelevant data packets through tcp.port == 8888, and save the filtered packets as a pcap file. ","date":"2023-04-10","objectID":"/capture-packets-for-mobile-apps/:4:0","tags":["packet capture","iPhone","macOS","command line tools"],"title":"Capture Packets for Mobile Apps","uri":"/capture-packets-for-mobile-apps/"},{"categories":["Note"],"content":"Many overseas shopping websites do not support China UnionPay bank cards, but the Bank of China MasterCard Debit Card can be applied online, with no application threshold and no annual fee. Info I mainly learned about this card on this blog 跨境通VISA/万事达借记卡介绍与网上支付体验, thanks to the author for sharing. There are many types of cards, but the application process is the same. I applied for the World Card. The card face is Monet’s sunrise impression, which is very beautiful. I mainly introduce my handling process, and other detailed information can refer to the above blog. ","date":"2023-03-23","objectID":"/apply-for-bank-of-china-mastercard-debit-card-online/:0:0","tags":["overseas payment"],"title":"Apply for Bank of China MasterCard Debit Card Online","uri":"/apply-for-bank-of-china-mastercard-debit-card-online/"},{"categories":["Note"],"content":"Apply Online Bank of China Shanghai Branch MasterCard Application https://cloud.bankofchina.com/sh/api/net/common/url/adr?id=kuajinggomastercard Open the above link on your phone and submit the information as required. The mailing address must be accurate to the house number, and the bank where the account is opened can be optional. Tip I encountered a problem at this step, I could not receive the verification code after filling in my phone number. I used China Mobile 和多号 to apply for a sub-number, and then I can receive the verification code with this sub-number. I found that the number that sent the verification code was 106980095566, not the customer service hotline 95566 of the Bank of China. The number 106980095566 can be unsubscribed by sending TD. I guess I should have unsubscribed from the SMS service of this number before, so I couldn’t receive the verification code. After applying, you can check the progress in the above link. If the application fails, you will also receive a text message reminder. When I applied for the first time, I wrote the address of the school, but it was not accurate to the house number, so the application failed. If the application is approved, you can receive the bank card by EMS in about two weeks. ","date":"2023-03-23","objectID":"/apply-for-bank-of-china-mastercard-debit-card-online/:1:0","tags":["overseas payment"],"title":"Apply for Bank of China MasterCard Debit Card Online","uri":"/apply-for-bank-of-china-mastercard-debit-card-online/"},{"categories":["Note"],"content":"Offline activation After receiving the bank card, go to any Bank of China outlet to activate it, and you need to bring your ID card and bank card. It can be activated at the smart counter, and the default password is the sixth to the second last digits of the ID card. The bound mobile phone number can be modified during activation, and the card will be linked to mobile banking after activation. ","date":"2023-03-23","objectID":"/apply-for-bank-of-china-mastercard-debit-card-online/:2:0","tags":["overseas payment"],"title":"Apply for Bank of China MasterCard Debit Card Online","uri":"/apply-for-bank-of-china-mastercard-debit-card-online/"},{"categories":["Note"],"content":"After activation After activation, the foreign currency must be transferred to the bank card, and foreign currency needs to be purchased through a Bank of China Class I card. In addition, the online payment function must be activated in mobile banking: Increase the limit in “限额设置 -\u003e 限额设置” Enable “限额设置 -\u003e 小额/凭签名免密(POS消费)” Enable “限额设置 -\u003e 磁条交易限额设置” Enable “支付设置 -\u003e 电子支付-手机支付” Enable “支付设置 -\u003e 电子支付-网上支付” Enable “支付设置 -\u003e 跨行支付 -\u003e 在线支付” Enable “支付设置 -\u003e 跨行支付 -\u003e 跨行代扣” Enable “支付设置 -\u003e 跨行支付 -\u003e 跨行订购” ","date":"2023-03-23","objectID":"/apply-for-bank-of-china-mastercard-debit-card-online/:3:0","tags":["overseas payment"],"title":"Apply for Bank of China MasterCard Debit Card Online","uri":"/apply-for-bank-of-china-mastercard-debit-card-online/"},{"categories":["Note"],"content":"Precautions for using the card Consumption or ATM cash withdrawal supports 19 foreign currencies such as US dollars, Euros, Japanese yen, and Hong Kong dollars, without currency conversion. Free of currency conversion fees, cross-border fees, and other consumption fees. The first overseas ATM cash withdrawal and balance inquiry fees are waived every month. Both foreign currency and foreign banknotes can be used for consumption and payment, and there will be no conversion fees when using them. If there is no transaction within 6 months after the debit card is opened, the non-counter business will be stopped. If the card is not used for a long time, the balance of the card must not be 0. When binding a card or making daily purchases, the balance in the USD account must be no less than $2. The account opening bank is the Shanghai branch. Businesses related to physical cards (such as the replacement of lost cards, replacement of expired cards, etc.) need to be handled at branches in Shanghai. Domestic transfers of foreign currency can only be made to the personal account and the account of the immediate family member. The foreign currency transfer between the personal non-Bank of China account and the account of the immediate family member needs to be handled at the counter. The payment will not be deducted immediately, but a certain proportion of funds will be frozen, and the deduction will be unfrozen after waiting for the bank to deposit the funds. The deposit time is usually two to three days. 100% of US dollar consumption is frozen, and 102% of non-US dollar consumption is frozen. Follow the “中国银行微银行” official account, bind the card, and enable account activation notifications. However, there are only notifications of deposit, not freezing notifications. SMS transaction reminders can be opened, for ¥2 per month, need to pay with a Bank of China Class I card. The order of deduction of foreign accounts is transaction banknotes account -\u003e transaction currency account -\u003e USD banknotes account -\u003e USD currency account. Only one foreign account can be used for full payment, and multiple accounts cannot be deducted. Cardless transactions only require the card number, validity period, and the last three digits of the signature area on the back, and do not require a transaction password, so the three pieces of information must be kept confidential. Don’t verify billing address, and don’t support AVS system verification. ","date":"2023-03-23","objectID":"/apply-for-bank-of-china-mastercard-debit-card-online/:4:0","tags":["overseas payment"],"title":"Apply for Bank of China MasterCard Debit Card Online","uri":"/apply-for-bank-of-china-mastercard-debit-card-online/"},{"categories":["Note"],"content":"Authorize sudo commands with Touch Id, so you don’t have to enter your password every time. In Terminal, enter the following command, then restart Terminal. sudo sed -i \".bak\" '2s/^/auth sufficient pam_tid.so\\'$'\\n/g' /etc/pam.d/sudo This command first backs up /etc/pam.d/sudo to /etc/pam.d/sudo.bak, then inserts auth sufficient pam_tid.so on the second line. If you want to restore the default settings, you can use the following command: sudo mv /etc/pam.d/sudo.bak /etc/pam.d/sudo ","date":"2023-03-22","objectID":"/authorize-sudo-commands-with-touch-id/:0:0","tags":["macOS","command line tools"],"title":"Authorize sudo Commands With Touch ID","uri":"/authorize-sudo-commands-with-touch-id/"},{"categories":["Note"],"content":"ChatGPT’s API is officially released and can be used in Python. Introducing ChatGPT API https://openai.com/blog/introducing-chatgpt-and-whisper-apis After registering an OpenAI account, create an API Key in https://platform.openai.com/account/api-keys. You can see in https://platform.openai.com/account/usage that there is a free trial usage of $18 in the account, which expires on April 1. This time the released ChatGPT model gpt-3.5-turbo is the same as the model used in the ChatGPT product. In addition, gpt-3.5-turbo-0301 has also been released, and this model is at least supported until June 1. The complete API usage guide can be found here: ChatGPT API Usage Guide https://platform.openai.com/docs/guides/chat In short, to use the ChatGPT API in Python, you need to install the openai Python package. # If you haven't installed openai, you can use the following command to install pip install openai # If you have installed openai, use the following command to update pip install openai --upgrade Then, import openai, and then use the openai.Completion.create function to call the API. Here is a simple Python script I wrote that can have a multi-turn conversation with ChatGPT. import os import openai # here you need to replace the API key with your own os.environ[\"OPENAI_API_KEY\"] = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\" openai.api_key = os.getenv(\"OPENAI_API_KEY\") messages = [ {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}, ] # this function is used to call the API def get_response(messages): completion = openai.ChatCompletion.create( model=\"gpt-3.5-turbo\", messages=messages, ) return completion.choices[0].message.content # type: ignore while True: try: print(\"type 'quit' to exit, type 'new' to begin a new conversation\") user_content = input(\"You: \") if user_content == \"quit\": break elif user_content == \"new\": messages = [ {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}, ] print(\"new conversation started\\n\") continue else: messages.append({\"role\": \"user\", \"content\": user_content}) response = get_response(messages) print(\"Assistant:\", response + \"\\n\") # append the response to the messages list for the next turn messages.append({\"role\": \"assistant\", \"content\": response}) except Exception as e: print(e) The output is as follows: Example type ‘quit’ to exit, type ’new’ to begin a new conversation You: What is the biggest animal in the world? Assistant: The biggest animal in the world is the blue whale. It can grow up to 100 feet long and weigh as much as 200 tons. type ‘quit’ to exit, type ’new’ to begin a new conversation You: Please write a poem about blue whales. Assistant: Majestic and mighty, The blue whale swims through the sea, Largest creature on earth, Behold its great beauty. A vast and gentle giant, Graceful in every move, Plunge deep into the ocean, Embrace the whale and groove. With a heart that’s enormous, And lungs as large as a car, Sing to the depths of the ocean, Your melodic, haunting bar. A creature so magnificent, Awe inspiring, and grand, Nowhere else found on earth, A true wonder of the land. Let us protect this great whale, So that it may flourish and thrive, For a world without the blue whale, Is a world less truly alive. type ‘quit’ to exit, type ’new’ to begin a new conversation You: new new conversation started type ‘quit’ to exit, type ’new’ to begin a new conversation You: 世界上最大的动物是什么? Assistant: 世界上最大的动物是蓝鲸。它们可以长达30米长,重达173吨,是地球上已知最大的动物。 type ‘quit’ to exit, type ’new’ to begin a new conversation You: 请写一首关于蓝鲸的诗。 Assistant: 在深深的海洋里 有一种生物,比海洋还大 它游荡于大海之中 它的名字叫做蓝鲸 蓝鲸身长三十米 重达一百七十三吨 它们是地球上最大的动物 不同寻常的存在 它们的歌声遥远而美丽 在海洋里有时听得见 它们善良而又神秘 是这片蔚蓝海洋之主 蓝鲸,你的身影 在海洋中,如此崇高 你的力量与恩宠 在人间,永世留存 type ‘quit’ to exit, type ’new’ to begin a new conversation You: quit ","date":"2023-03-03","objectID":"/using-the-chatgpt-api-in-python/:0:0","tags":["ChatGPT","Python"],"title":"Using the ChatGPT API in Python","uri":"/using-the-chatgpt-api-in-python/"},{"categories":["Note"],"content":"On iOS and iPadOS, you can enable private WiFi address to randomize MAC address in settings. There is no such option on macOS, but we can do it through the command line. I found SpoofMAC on Github, which is a Python script that works not only on macOS but also on Windows and Linux. It can randomize MAC address and set MAC address to any value. SpoofMAC https://github.com/feross/spoofmac Installing SpoofMAC is simple, just pip install SpoofMAC. ","date":"2023-03-02","objectID":"/randomize-mac-address-for-macos/:0:0","tags":["macOS","Python","command line tools"],"title":"Randomize MAC Address for macOS","uri":"/randomize-mac-address-for-macos/"},{"categories":["Note"],"content":"Usage Here is an example of using SpoofMAC to modify MAC address on macOS. Tip To run spoof-mac directly in the terminal, you need to add bin to PATH. If you are using zsh, you can add it in ~/.zshrc, for example, export PATH=$PATH:~/Library/Python/3.9/bin. First, list all available devices spoof-mac list You will get an output like this Example - “Ethernet” on device “en0” with MAC address 70:56:51:BE:B3:00 - “Wi-Fi” on device “en1” with MAC address 70:56:51:BE:B3:01 - “Bluetooth PAN” on device “en1” Then, randomize MAC address sudo spoof-mac randomize en1 # or sudo spoof-mac randomize wifi To restore MAC address, just run sudo spoof-mac reset en1 # or sudo spoof-mac reset wifi ","date":"2023-03-02","objectID":"/randomize-mac-address-for-macos/:1:0","tags":["macOS","Python","command line tools"],"title":"Randomize MAC Address for macOS","uri":"/randomize-mac-address-for-macos/"},{"categories":["Note"],"content":"pwgen can generate random and secure passwords in the command line! pwgen https://pwgen.sourceforge.io/ pwgen can be installed with Homebrew: brew install pwgen. The usage is also very simple. For example, pwgen -sy 50 is to generate a 50-character password, including uppercase and lowercase letters, numbers and special characters. More usage can be viewed with pwgen -h: Note Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ] Options supported by pwgen: -c or –capitalize Include at least one capital letter in the password -A or –no-capitalize Don’t include capital letters in the password -n or –numerals Include at least one number in the password -0 or –no-numerals Don’t include numbers in the password -y or –symbols Include at least one special symbol in the password -r or –remove-chars= Remove characters from the set of characters to generate passwords -s or –secure Generate completely random passwords -B or –ambiguous Don’t include ambiguous characters in the password -h or –help Print a help message -H or –sha1=path/to/file[#seed] Use sha1 hash of given file as a (not so) random generator -C Print the generated passwords in columns -1 Don’t print the generated passwords in columns -v or –no-vowels Do not use any vowels so as to avoid accidental nasty words ","date":"2023-02-28","objectID":"/pwgen-random-password-generator/:0:0","tags":["command line tools"],"title":"Pwgen: a Random Password Generator","uri":"/pwgen-random-password-generator/"},{"categories":["Note"],"content":"I have been using the LoveIt Hugo theme since I built my website in 2021, and not much has changed. This time, I migrated to the FixIt theme, which not only fixed some problems in LoveIt, but also brought more new features and optimizations. By the way, the comment system has migrated from Valine to Waline. FixIt https://fixit.lruihao.cn/ Since FixIt is based on LoveIt, migrating to Fixit is relatively easy. After some tweaking, the main changes to my website are as follows: Enable Twemoji Migrate the comment system from Valine to Waline, add image and gif, article reactions, etc. Add Font Awesome icons to the menu bar Add Github corner Change Mapbox map style Add donation function Add PWA support Add website creation time display Add BuSuanzi visit statistics Add website word count Change tags to word cloud display Add PangguZhibai Add page watermark Add reading progress bar Add page loading progress bar Now FixIt is still continuously and actively updating, and I will continue to follow up and continuously improve my website. ","date":"2023-02-27","objectID":"/my-website-has-a-new-theme/:0:0","tags":["My Website","Hugo"],"title":"My Website Has a New Theme","uri":"/my-website-has-a-new-theme/"},{"categories":["Note"],"content":"The terminal of macOS is very good, but it feels like it’s missing something, so I strengthened it. There are many people who recommend using Oh My Zsh, but I don’t know why, I often have some problems when I use Oh My Zsh, so this time I didn’t use it. ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:0:0","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"Beautify I used starship to beautify the terminal, which is a lightweight, fast, cross-platform command line theme. starship https://starship.rs/ Before installing starship, you need to install the Nerd Font font, such as Fira Code Nerd Font. You can use Homebrew to install it, and then enable the Fira Code Nerd Font font in the terminal settings. brew tap homebrew/cask-fonts brew install --cask font-fira-code-nerd-font Then, use Homebrew to install starship: brew install starship. Add eval \"$(starship init zsh)\" at the end of ~/.zshrc, and then execute source ~/.zshrc. Reopen the terminal, and you can see the effect. More custom configuration can be found in the guide. ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:1:0","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"Extension ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:2:0","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"1. zsh-fast-syntax-highlighting This plugin can highlight the content entered on the command line, making your terminal more beautiful. zsh-fast-syntax-highlighting https://github.com/zdharma-continuum/fast-syntax-highlighting brew install zsh-fast-syntax-highlighting Info To activate the syntax highlighting, add the following at the end of your .zshrc: source $HOMEBREW_PREFIX/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:2:1","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"2. zsh-autosuggestions This plugin can automatically complete the command line based on the history. zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions brew install zsh-autosuggestions Info To activate the autosuggestions, add the following at the end of your .zshrc: source $HOMEBREW_PREFIX/share/zsh-autosuggestions/zsh-autosuggestions.zsh You will also need to restart your terminal for this change to take effect. ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:2:2","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"3. zsh-completions This plugin can also complete the command line. zsh-autocomplete https://github.com/marlonrichert/zsh-autocomplete brew install zsh-autocomplete Info Add at or near the top of your .zshrc file (before any calls to compdef): source $HOMEBREW_PREFIX/share/zsh-autocomplete/zsh-autocomplete.plugin.zsh Remove any calls to compinit from your .zshrc file. If you’re using Ubuntu, add to your .zshenv file: skip_global_compinit=1 Then restart your shell. ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:2:3","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"4. zsh-autopair This plugin can automatically complete the brackets, and quotes. zsh-autopair https://github.com/hlissner/zsh-autopair brew install zsh-autopair Info To activate autopair, add the following at the end of your .zshrc: source $HOMEBREW_PREFIX/share/zsh-autopair/autopair.zsh You will also need to restart your terminal for this change to take effect. ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:2:4","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"5. z This plugin can quickly jump to the directory you want to go to. z https://github.com/rupa/z brew install z Info For Bash or Zsh, put something like this in your $HOME/.bashrc or $HOME/.zshrc: . $HOMEBREW_PREFIX/etc/profile.d/z.sh In addition, you can also add setopt autocd to your .zshrc file, which will automatically change the current directory to the directory you entered. ","date":"2023-02-26","objectID":"/strengthen-macos-terminal/:2:5","tags":["macOS","command line tools"],"title":"Strengthen macOS Terminal","uri":"/strengthen-macos-terminal/"},{"categories":["Note"],"content":"I used to put the pictures of my website on the storage space of Qiniu Cloud. Although Qiniu Cloud is not bad, the traffic under the https protocol needs to be charged. So, I used jsDelivr and Githubc repository to build a free image hosting service. ","date":"2023-02-25","objectID":"/build-a-image-hosting-service-with-jsdelivr-and-github-repository/:0:0","tags":["Github","My Website","command line tools"],"title":"Build a Image Hosting Service With jsDelivr and Github Repository","uri":"/build-a-image-hosting-service-with-jsdelivr-and-github-repository/"},{"categories":["Note"],"content":"The method is very simple Create a public Github repository Upload the picture to the repository Get the link of the picture, such as https://cdn.jsdelivr.net/gh/user/repository/image.jpeg, user is your Github username, repository is your repository name, image.jpeg is the name of the picture you uploaded In addition, this can also be combined with the previous introduction of ImageMagick, you can write a simple script, automatically compress the picture and upload it to the Github repository, and then get the link of the picture. ","date":"2023-02-25","objectID":"/build-a-image-hosting-service-with-jsdelivr-and-github-repository/:1:0","tags":["Github","My Website","command line tools"],"title":"Build a Image Hosting Service With jsDelivr and Github Repository","uri":"/build-a-image-hosting-service-with-jsdelivr-and-github-repository/"},{"categories":["Note"],"content":"I found ImageMagick, which is a powerful image processing tool that can be used in the command line. Not only can it be used to compress images, but it can also be used for many other things. ImageMagick https://imagemagick.org/ ImageMagick can be installed through Homebrew: brew install imagemagick. It can be used to compress images in the command line. For example, I have an image image.png, and I want to compress it. I can use the following command: convert image.png -quality 80% image.png And, you can compress the image while converting the image format at the same time. If I want to compress the image and convert it to JPEG format, I can use the following command: convert image.png -quality 80% image.jpg ImageMagick also has many other features, which can be explored according to the official documentation. ","date":"2023-02-24","objectID":"/use-imagemagick-to-compress-the-image-in-the-command-line/:0:0","tags":["command line tools"],"title":"Use ImageMagick to Compress the Image in the Command Line","uri":"/use-imagemagick-to-compress-the-image-in-the-command-line/"},{"categories":["Note"],"content":"Since I need to use both Chinese and English input methods at the same time, I often switch between Chinese and English. Sometimes I open Terminal and input Chinese. So I found a tool called KeyboardHolder, which can help us automatically switch input methods. KeyboardHolder https://keyboardholder.leavesc.com/en-us/ You can also install it with Homebrew: brew install --cask keyboardholder. It can set the input method for each app when it starts or switches from the background to the foreground, such as setting the English input method when Terminal starts. In addition, it can display the input method switch prompt at the location of the mouse, so you don’t need to transfer the focus to the menu bar to check the input method status. Info This feature has been built into macOS 14. ","date":"2023-02-23","objectID":"/keyboardholder-automatically-switch-input-methods/:0:0","tags":["macOS"],"title":"KeyboardHolder: Automatically Switch Input Methods","uri":"/keyboardholder-automatically-switch-input-methods/"},{"categories":["Note"],"content":"I suddenly found this Kerberos in the notification settings, what is it? I asked Bing and it said: Quote Hello, this is Bing. Kerberos is an authentication system that allows you to securely access various services on the network. Kerberos in Mac is based on the MIT Kerberos implementation and provides Kerberos v5 and v4 protocols, GSSAPI, a graphical authentication interface and a ticket cache. You can use the command line or the Ticket Viewer app to manage your Kerberos tickets. https://uit.stanford.edu/service/ess/mac/docs/kerberos_macOS https://web.mit.edu/macdev/www/kerberos.html https://support.apple.com/en-gb/guide/deployment/depe6a1cda64/web https://support.apple.com/en-gb/guide/deployment/depe6a1cda64/web It seems that this Kerberos is included in macOS, it is located in /System/Library/CoreServices/Applications/Ticket Viewer.app, and it is not a malicious program. ","date":"2023-02-22","objectID":"/what-is-kerberos-in-mac/:0:0","tags":["macOS","Bing"],"title":"What Is Kerberos in Mac?","uri":"/what-is-kerberos-in-mac/"},{"categories":["Note"],"content":"Icons can be resized by adjusting the number of icons per row and column of Launchpad. ","date":"2023-02-21","objectID":"/modify-the-icons-size-in-macos-launchpad/:0:0","tags":["macOS"],"title":"Modify the Icons Size in MacOS Launchpad","uri":"/modify-the-icons-size-in-macos-launchpad/"},{"categories":["Note"],"content":"method Execute the following commands in the Terminal: # For example, set to 8 columns defaults write com.apple.dock springboard-columns -int 8 # For example, set to 6 lines defaults write com.apple.dock springboard-rows -int 6 # Reset Launchpad defaults write com.apple.dock ResetLaunchPad -bool TRUE # Restart the Dock killall Dock Restore default settings: defaults write com.apple.dock springboard-rows Default defaults write com.apple.dock springboard-columns Default defaults write com.apple.dock ResetLaunchPad -bool TRUE killall Dock ","date":"2023-02-21","objectID":"/modify-the-icons-size-in-macos-launchpad/:1:0","tags":["macOS"],"title":"Modify the Icons Size in MacOS Launchpad","uri":"/modify-the-icons-size-in-macos-launchpad/"},{"categories":["Note"],"content":"Suddenly, I found that there are two Edge Dev on my Mac, 111.0.1660.13 and 111.0.1660.12, and both of them can launch normally. I want to keep the latest version and uninstall the old one. ","date":"2023-02-19","objectID":"/multiple-versions-of-edge-browser-appear-on-mac/:0:0","tags":["macOS","Browser"],"title":"Multiple Versions of Edge Browser Appear on Mac","uri":"/multiple-versions-of-edge-browser-appear-on-mac/"},{"categories":["Note"],"content":"method ","date":"2023-02-19","objectID":"/multiple-versions-of-edge-browser-appear-on-mac/:1:0","tags":["macOS","Browser"],"title":"Multiple Versions of Edge Browser Appear on Mac","uri":"/multiple-versions-of-edge-browser-appear-on-mac/"},{"categories":["Note"],"content":"1 Take the Dev version as an example. Switch the directory to the following location cd /Applications/Microsoft\\ Edge\\ Dev.app/Contents/Frameworks/Microsoft\\ Edge\\ Framework.framework/Versions You can also press control + shift + G in the Finder to go to the location ","date":"2023-02-19","objectID":"/multiple-versions-of-edge-browser-appear-on-mac/:1:1","tags":["macOS","Browser"],"title":"Multiple Versions of Edge Browser Appear on Mac","uri":"/multiple-versions-of-edge-browser-appear-on-mac/"},{"categories":["Note"],"content":"2 Execute ls -l, and you will see similar output Example drwxrwxr-x 14 user admin 448 Feb 11 11:32 111.0.1660.12 drwxrwxr-x 14 user admin 448 Feb 17 08:54 111.0.1660.13 lrwxrwxr-x 1 user admin 13 Feb 17 08:54 Current -\u003e 111.0.1660.13 Or click Current in the Finder to confirm the version linked to ","date":"2023-02-19","objectID":"/multiple-versions-of-edge-browser-appear-on-mac/:1:2","tags":["macOS","Browser"],"title":"Multiple Versions of Edge Browser Appear on Mac","uri":"/multiple-versions-of-edge-browser-appear-on-mac/"},{"categories":["Note"],"content":"3 Use rm -rf to remove other older versions, or you can also delete them in Finder ","date":"2023-02-19","objectID":"/multiple-versions-of-edge-browser-appear-on-mac/:1:3","tags":["macOS","Browser"],"title":"Multiple Versions of Edge Browser Appear on Mac","uri":"/multiple-versions-of-edge-browser-appear-on-mac/"},{"categories":["Note"],"content":"4 The last step, this step can also be done in the Finder cd ~/Library/Application\\ Support/Microsoft rm -rf EdgeUpdater ","date":"2023-02-19","objectID":"/multiple-versions-of-edge-browser-appear-on-mac/:1:4","tags":["macOS","Browser"],"title":"Multiple Versions of Edge Browser Appear on Mac","uri":"/multiple-versions-of-edge-browser-appear-on-mac/"},{"categories":["Note"],"content":"Since joining the waitlist on February 11th, I finally received an email today that I can use the new Bing. Bug I couldn’t wait to open Edge Dev and enter CHAT, but I soon found that I couldn’t input all the characters normally in the input box. I tried it again in Safari and it worked perfectly, so there is probably something wrong with Edge Dev. After a few rounds of conversations with the new Bing, it felt like it was a bit lacking in conversational enthusiasm, often asking me to change the subject. Moreover, the prompt “This has been lovely, but you’ve reached your daily limit. Chat again tomorrow?” appeared within a few minutes. I have to say that a very useful feature of the new Bing is that it can obtain information from the web pages and documents we are reading. I tested it, opened a local PDF file with Edge Dev, clicked the Discover button to chat, and the new Bing can summarize the main points in this file. In addition, it can also easily generate some text in Discover. According to my experience, I think the new Bing is really good, and I am very much looking forward to the official version in the future. ","date":"2023-02-18","objectID":"/you-re-in-welcome-to-the-new-bing/:0:0","tags":["Bing","ChatGPT","Browser"],"title":"You're in! Welcome to the New Bing!","uri":"/you-re-in-welcome-to-the-new-bing/"},{"categories":["Journal"],"content":"Delicious Creamy Fruit Cake! Based on two cakes last year, this time added cream and fruit and put a few Oreos. The taste was more varied. The only downside was that the cake base was not sweet and soft enough. It tasted a bit like mantou(Chinese steamed bun)😂. ","date":"2023-02-15","objectID":"/creamy-fruit-cake-an-upgraded-version/:0:0","tags":["cake"],"title":"Creamy Fruit Cake -- An Upgraded Version🍰","uri":"/creamy-fruit-cake-an-upgraded-version/"},{"categories":["Note"],"content":"Visited Lite is a userscript to customize the color of visited links, and Color Links is a browser extension with similar function. A few days ago, Microsoft launched new versions of Bing and Edge browsers combined with GPT. I read their introductions on the Internet and felt they were really good. And last year I experienced ChatGPT for the first time, so this time I am looking forward to the new version of Bing and Edge and applied to join the waitlist. Question In the process of using Bing, I suddenly discovered a problem. In Bing’s search results, the visited links and unvisited links were both purple, it’s difficult to distinguish which links are visited and which are not. I have been using Google before, the unvisited links are blue, and the visited links are purple. I didn’t find the relevant settings in Bing and I didn’t know where the problem was. So I looked for some userscripts or browser extensions to solve this problem. ","date":"2023-02-13","objectID":"/visited-lite-script-that-mark-all-visited-links-as-custom-color/:0:0","tags":["Bing","ChatGPT","Browser","Userscripts","Chrome Extensions"],"title":"Visited Lite \u0026 Color Links: mark all visited links as custom color","uri":"/visited-lite-script-that-mark-all-visited-links-as-custom-color/"},{"categories":["Note"],"content":"Visited Lite I found Visited Lite, which can customize the color of visited links for all websites, not just Bing’s. I installed this userscript in Edge’s Tampermonkey extension. Visited Lite marks all visited links with bold color. However, some web pages may not need this function, and they can be excluded from the Tampermonkey](https://www.tampermonkey.net/) extension. ","date":"2023-02-13","objectID":"/visited-lite-script-that-mark-all-visited-links-as-custom-color/:1:0","tags":["Bing","ChatGPT","Browser","Userscripts","Chrome Extensions"],"title":"Visited Lite \u0026 Color Links: mark all visited links as custom color","uri":"/visited-lite-script-that-mark-all-visited-links-as-custom-color/"},{"categories":["Note"],"content":"Color Links After that, I found Color Links in the chrome web store. The main difference from Visited Lite is that Color Links need to manually enable the marking function for each website. ","date":"2023-02-13","objectID":"/visited-lite-script-that-mark-all-visited-links-as-custom-color/:2:0","tags":["Bing","ChatGPT","Browser","Userscripts","Chrome Extensions"],"title":"Visited Lite \u0026 Color Links: mark all visited links as custom color","uri":"/visited-lite-script-that-mark-all-visited-links-as-custom-color/"},{"categories":["Note"],"content":"Yesterday I used the texliveonfly package and got env: python: No Such File or Directory directly. I tried to execute python, and a prompt from Xcode Command Line Tools popped up, saying that I needed to download something, and it downloaded Python3.9, while I already had Python3.8🙃. I tried to create a symbolic link with ln, but it didn’t work. Success I thought since texliveonfly was written in Python, I could edit it directly. So I found /Library/TeX/texbin/texliveonfly and changed the first line of this file from #!/usr/bin/env python to #!/usr/bin/env python3, which solved the problem. ","date":"2023-01-23","objectID":"/texliveonfly-env-python-no-such-file-or-directory/:0:0","tags":["LaTeX","Python","macOS"],"title":"texliveonfly, env: python: No Such File or Directory","uri":"/texliveonfly-env-python-no-such-file-or-directory/"},{"categories":["Note"],"content":"LeetCode 66.Plus One, is an easy problem. I just want to practice Java, it’s been a long time since I wrote Java. My idea is to traverse from the end to the beginning, if the current digit is 9, then carry, if not, then add 1, and then return the result. If the last digit is 9, then we need to add a 1 at the beginning, at this time we need to create a new array, and then copy the original array. class Solution { public int[] plusOne(int[] digits) { int end = digits.length - 1; int[] result = new int[end + 1]; boolean carry = false; result[end] = digits[end] + 1; if (result[end] == 10) { result[end] = 0; carry = true; } for (int i = end - 1; i \u003e= 0; --i) { result[i] = digits[i]; if (carry) { result[i] += 1; if (result[i] == 10) { result[i] = 0; carry = true; } else { carry = false; } } } if (carry) { int[] tmp = result; result = new int[end + 2]; result[0] = 1; for (int i = 1; i \u003c end + 2; ++i) { result[i] = tmp[i - 1]; } } return result; } } ","date":"2023-01-22","objectID":"/leetcode-66/:0:0","tags":["algorithms","Java","LeetCode"],"title":"LeetCode 66","uri":"/leetcode-66/"},{"categories":["Note"],"content":"Today my dad drove me to a place. After I got off the car and walked for 3 minutes, I suddenly found that my mobile phone was missing… I hurried back to the same place to look for my mobile phone, but I couldn’t find it. Finally, I borrowed a mobile phone from the traffic police on the side of the road and called my father to confirm that my mobile phone was left in the car. Although Find My has been set to send a notification on the Apple Watch when I leave my iPhone, it seems that this function needs to be at a relatively long distance to take effect. So I found Phone Buddy: Phone Buddy https://apps.apple.com/us/app/phone-buddy-phone-lost-alert/id1451559391 The price is $4.99, I bought a US App Store Gift Card with Alipay to recharge and purchase this App. Note After downloading Phone Buddy, turn on Lost Phone Alert on the Apple Watch, and when the Apple Watch loses the Bluetooth connection with the iPhone, an alert will be sent to the Apple Watch. And there can also be a Distance Alert. When the Bluetooth signal strength between the Apple Watch and iPhone decays below the set threshold with the increase of distance, an alert can also be issued, so that it can be one more time before the Bluetooth connection is completely disconnected. Similarly, you can also set an alert on the iPhone after the Apple Watch is disconnected, which can prevent the Apple Watch from being lost or forgotten. The only downside is that this App will shorten the battery life of the Apple Watch, but compared to losing my iPhone, this price is acceptable. ","date":"2023-01-18","objectID":"/use-phone-buddy-on-apple-watch-to-prevent-forgotten-iphone/:0:0","tags":["Apple Watch","iPhone"],"title":"Use Phone Buddy on Apple Watch to Prevent Forgotten iPhone","uri":"/use-phone-buddy-on-apple-watch-to-prevent-forgotten-iphone/"},{"categories":["Journal"],"content":"The first semester at UCAS passed quickly, and I feel that the experience of this semester is very rich. I arrived in Huaibei Town, Huairou District, Beijing on August 17, 2022. I visited Yanqi Lake in the afternoon. Yanqi Lake is a very big lake. There are many trees🌳 by the lake, many boats🛶 on the lake, and many people by the lake. There is also a trail leading to somewhere on the mountain by the lake. I walked on this road for a long time and felt good. Unfortunately, the road was interrupted due to construction🚧. Later, I learned about this road and the viewing platform of UCAS is connected. I saw a lot of birds🐦 on the mountain by the lake. They flew on the lake and chirped on the trees by the lake. Yanqi Lake After staying in a farmhouse inn in the village next to Yanqi Lake for one night, I went to UCAS early the next morning. It rained🌧️ all day, and my clothes and shoes were soaked, but when I first arrived at school, everything felt so fresh and I was in a good mood🙂. The lotus pond in the West District of Yanqi Lake Campus of UCAS The sunset Great Wall on the Hill With the nucleic acid test every two days, this semester started. The quality and difficulty of the courses offered by UCAS are indeed higher than those offered by NCUT, and I feel that I have gained more. In addition to class, I often ride a bicycle🚲 around the school to see the scenery of the campus. Because the school is backed by mountains and Yanqi Lake, the ecological environment of the school is very good. There are often little animals🐱, and it is said that there are beasts of prey such as boars🐗 and snakes🐍. Mountains in Autumn Yellow leaves Tree in sunlight Hawthorn tree Yanqi North Road I have to say that UCAS has planted many fruit trees in the mountains. After the autumn harvest, we ate a lot of free fruits. Pear In the early morning of October 15th, our entire dormitory was suddenly notified to be quarantined on the spot, and each of us was sent a hearty breakfast and a large bucket of water. Before I finished eating, We were notified again that the quarantine is over, which is inexplicable😅. Breakfast At the end of November, the school became not so peaceful. As the Omicron epidemic became more serious in winter, many colleges and universities in Beijing began to arrange for students to return home. In the beginning, UCAS still required students to complete all the exams at school, and then finally allowed students to return to their hometowns on November 29. All kinds of gossip spread in the school for a while: some people said that there was a student who tested positive for nucleic acid in the school, and all the students could not go home, and they might be quarantined in the dormitory; someone said that after leaving the school and entering the urban area of Beijing, someone would search the mobile phone at the train station or other places… It feels a bit panicky. Since the city where my family is located was under lockdown, I didn’t know when it would end, so I decided to stay in school. It is said that if there is an epidemic on campus, the cafeteria may not be able to cook normally, so I quickly stocked up some food. At that time, many express delivery services were interrupted, and JD Express also became very slow. During those few days, most of the students left the school and went home, and the school was quiet. Around December 5, there was a sudden major change in the epidemic prevention policy, and the nucleic acid test every two days was finally ended. But at this time, infected people began to appear in the school, and I also prepared 2 boxes of compound acetaminophen capsules. After waking up on the morning of December 19th, I felt my throat was dry and a little sore, and there was a lot of nasal discharge. I must have an infection. That night, my sports watch kept warning me my heart🫀 was beating very fast at around 120BMP. I could hear my heart beating while sitting quietly. I was so scared and I lay down on the bed. My w","date":"2023-01-17","objectID":"/first-semester-at-ucas/:0:0","tags":["stroll","UCAS"],"title":"First Semester at UCAS","uri":"/first-semester-at-ucas/"},{"categories":["Note"],"content":"If you are using macOS, you can switch to the Documents directory by executing cd documents in ~, but you cannot use Tab to complete it. The solution is to add the following code to ~/.zshrc: autoload -Uz compinit \u0026\u0026 compinit zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' Open a new terminal and you will see the effect. ","date":"2022-12-09","objectID":"/zsh-tab-completion-with-case-insensitivity/:0:0","tags":["command line tools","macOS"],"title":"zsh: Tab Completion With Case Insensitivity","uri":"/zsh-tab-completion-with-case-insensitivity/"},{"categories":["Note"],"content":"It only takes 5 minutes to turn the WeChat official account into a robot🤖. I registered a WeChat official account before, but it has been idle, so I want to turn it into a robot and play a little role. ","date":"2022-11-16","objectID":"/turn-idle-wechat-official-account-into-a-robot/:0:0","tags":["WeChat"],"title":"Turn Idle WeChat Official Account Into a Robot","uri":"/turn-idle-wechat-official-account-into-a-robot/"},{"categories":["Note"],"content":"method Use WeChat scan QR code to log in 微信对话开放平台 Set the name of the robot on the robot creation page to complete the robot creation Turn on the robot’s “预置技能” as needed, such as English translation, weather, stocks, news, jokes, etc. Bind the WeChat official account in “应用绑定” Publish in “上线发布” Really simple! ","date":"2022-11-16","objectID":"/turn-idle-wechat-official-account-into-a-robot/:1:0","tags":["WeChat"],"title":"Turn Idle WeChat Official Account Into a Robot","uri":"/turn-idle-wechat-official-account-into-a-robot/"},{"categories":["Note"],"content":"Since the laptop uses a lithium battery, a long-term connection to the power adapter will cause the battery to always be at a high percentage, which will shorten the life of the battery. Therefore, keeping the percentage between 20% and 80% can delay the decay of the battery. For MacBook, I found software that can solve this problem: AlDente https://github.com/davidwernhart/AlDente-Charge-Limiter It can be downloaded from Github, or you can use Homebrew, brew install --cask aldente. After launching AlDente, this software appears in the menu bar, which can easily control the maximum charging percentage of the MacBook. Afterward, it can be observed that the power adapter is connected, but the battery is not charging. ","date":"2022-10-11","objectID":"/aldente-limit-macbook-maximum-charging-percentage/:0:0","tags":["macOS"],"title":"AlDente: Limit MacBook Maximum Charging Percentage","uri":"/aldente-limit-macbook-maximum-charging-percentage/"},{"categories":["Note"],"content":"There are always some software icons that are not compatible with macOS. iconsur can generate rounded rectangle icons for them to beautify our macOS. iconsur’s Github homepage: iconsur https://github.com/rikumi/iconsur It can be downloaded in Releases. You can also use Homebrew: brew install iconsur, or npm: npm install -g iconsur. iconsur finds the most similar iOS app for the software in the App Store and replaces the icon of this software with the icon of the iOS app. For example: sudo iconsur set /Applications/Microsoft\\ Word.app/ In addition, iconsur can also generate icons locally for the software. For example: For another usage, please refer to Github or execute iconsur help. ","date":"2022-09-17","objectID":"/iconsur-generate-rounded-rectangle-icons-for-macos-third-party-software/:0:0","tags":["macOS","command line tools"],"title":"iconsur: Generate Rounded Rectangle Icons for MacOS Third-Party Software","uri":"/iconsur-generate-rounded-rectangle-icons-for-macos-third-party-software/"},{"categories":["Journal"],"content":"After more than half a month of training, I successfully got my driving license! Thanks to each of my coaches for their patient guidance! driving license I also went around the driving school. It’s built on a hill and has a wide field of vision. Sun This driving school even has a few ponies. Pony Goose \u0026 Duck ","date":"2022-08-13","objectID":"/i-got-my-driving-license/:0:0","tags":["stroll"],"title":"I Got My Drivers License🚘","uri":"/i-got-my-driving-license/"},{"categories":["Project"],"content":"NCUT-Pot is my graduation project, it’s a honeypot. This honeypot supports Telnet and SSH two protocols, simulates the Linux system, and stores hackers’ data in the SQL database. In addition, it also sends alerts to users via SMS and email. Users can customize commands and directories. Info For more details about NCUT-Pot please visit https://github.com/kayak4665664/FF-Pot(now renamed FF-Pot). ","date":"2022-07-14","objectID":"/ncut-pot/:0:0","tags":["graduation project","NCUT","Github"],"title":"NCUT-Pot","uri":"/ncut-pot/"},{"categories":["Journal"],"content":"Since the end of the graduation project, I have been looking forward to the letter of admission every day, and it is finally here! letter of admission Haha, the campus card is here too. I’m very much looking forward to the new semester at UCAS, but I have to report on August 18, and I’m going to the driving school. I feel that my vacation has ended before it even started🥹 degree certificate graduation certificate I also received my graduation certificate and degree certificate. I miss those happy days at NCUT. ","date":"2022-07-13","objectID":"/august-18-a-new-beginning/:0:0","tags":["NCUT","UCAS"],"title":"August 18, a New Beginning","uri":"/august-18-a-new-beginning/"},{"categories":["Journal"],"content":"The graduation project is finally coming to an end, and the final defense will be held on the afternoon of June 9! Now that I have completed most of the work on my graduation project, these last two weeks have been relatively relaxing. But I am now quarantined and can only stay in the room every day🙃, and today is the 4th day. At noon on May 27, I went to the canteen to have lunch as usual. As soon as I returned to my dormitory, I suddenly received a notice from the school asking graduates to leave the school as soon as possible. I realized right away that this would be my last few days at the North China University of Technology. the notice I calmed down a bit and immediately started planning what I had to do before I left school. The first thing to consider is my luggage. Fortunately, the school promised that it can be delivered for free. Otherwise, I can’t afford the cost of expressing so many things. However, I didn’t have a cardboard box for packing. I asked the counselor and he only said it would be released later. I felt his answer was too vague, and I decided to go buy a few cardboard boxes myself. I went to the school express outlet and found the boss there. He told me that our college had taken more than 100 cardboard boxes from him before. I estimated that a student should only get 1 cardboard box. So, I bought 4 large cardboard boxes from the boss for ¥45. With the cardboard box, I went back to my dormitory to pack the luggage. At the same time, I had to report to the community where my family live. I contacted the staff in the community and she told me that I would be quarantined for 7 days and then quarantined at home for 7 days. I didn’t think this is reasonable. I have taken dozens of nucleic acid tests during school, and they have never been positive, and the school has always been closed. People outside the school can’t come in, and people inside the school can’t get out. I don’t think I should be quarantined for 7 days. And as far as I know, some places do not require centralized quarantine for students returning from Beijing. I explained it to her, but it didn’t work. Fortunately, centralized quarantine is free, otherwise, it will cost a lot of money. In those days, I saw the news that some college students were quarantined after returning home and charged ¥500 a day. After packing my luggage, I felt a little hot and I noticed that my hair was a little longer. As soon as I thought that I was going to be quarantined for half a month, I went to the barber shop to cut my hair short. In the evening, the counselor finally informed us that we could go get the cardboard box, and I got a cardboard box and a sack. With the 4 large cardboard boxes I bought, it was just right. On the morning of May 28, I went to the supermarket to buy a marker and I had to mark my address on the box. I walked into the dormitory building, and a dormitory administrator who was familiar with me told me that I could take my luggage to the express outlet now, and reminded me to hurry up. Considering that I have to move 4 cartons and 1 sack from the dormitory to the outlet, it is not easy to rely on only two hands, so I went to the outlet and borrowed a flatbed trolley from the boss. I went back to my dormitory, marked all 5 items with my information, put them all on the trolley, and all of them were shipped to the express outlet at once. the flatbed trolley Since the notice of the graduates leaving the school was rushed, the boss of the express outlet frankly said that they did not know how to handle the luggage of so many students, and there were only two people in the entire outlet including him. When I pushed the flat trolley to the outlet, I saw that there were already many boxes piled up outside. I was a little worried that so many boxes would be confused, so I asked the boss to affix notes to my luggage first so that I could also track it easily. By the time I had dealt with all this, it was already past noon. When I arrived at the c","date":"2022-06-04","objectID":"/next-week-i-will-have-my-graduation-project-defense/:0:0","tags":["graduation project","NCUT"],"title":"Next Week I Will Have My Graduation Project Defense","uri":"/next-week-i-will-have-my-graduation-project-defense/"},{"categories":["Note"],"content":"Today I learned a way to directly use Alipay to buy US App Store gift cards, so I don’t need to go to Taobao and Xianyu to buy them in the future! ","date":"2022-05-21","objectID":"/buy-us-app-store-gift-cards-with-alipay/:0:0","tags":["overseas payment"],"title":"Buy US App Store Gift Cards With Alipay","uri":"/buy-us-app-store-gift-cards-with-alipay/"},{"categories":["Note"],"content":"method Open Alipay Switch to San Francisco in the upper left corner of the home page Search for “出境” and select “出境” in the search results Select “折扣礼卡” Swipe to the bottom of the page and click “更多大牌折扣礼卡” Search for “App Store” Enter the correct email account Enter the value you want to buy, at least $2, “Purchase card” ","date":"2022-05-21","objectID":"/buy-us-app-store-gift-cards-with-alipay/:1:0","tags":["overseas payment"],"title":"Buy US App Store Gift Cards With Alipay","uri":"/buy-us-app-store-gift-cards-with-alipay/"},{"categories":["Journal"],"content":"Workers of the world, unite! Work together to defend our rights and fight for a fairer and better world. ","date":"2022-04-30","objectID":"/international-workers-day/:0:0","tags":[],"title":"Celebrating International Workers' Day","uri":"/international-workers-day/"},{"categories":["Journal"],"content":"Today I participated in the thesis proposal through the Tencent Meeting. The original plan was to start at 1:30 p.m. I don’t know why we waited until 2 p.m😶. There were 24 students and 3 judges in this thesis proposal this afternoon. I was number 12 and waited until 4 p.m. to finally get my turn. Overall, it went relatively smoothly, but there was a teacher who was studying computer networks coincidentally, and my topic involved a lot of network stuff, so I was questioned closely. After my turn, because the teacher didn’t say we could withdraw, I just continued to stay in the meeting to watch others. An unnamed student was recommended to study at the Institute of Computing Technology, Chinese Academy of Sciences for postgraduate study without examination, his graduation project was in cooperation with Huawei. He said that the results of his graduation project would beat the previous work of his supervisor, and he was determined to submit a paper to the top conference as well👍. Such excellent classmates inspire me to do my work better, and keep working hard👍. ","date":"2022-03-09","objectID":"/todays-thesis-proposal/:0:0","tags":["graduation project","NCUT"],"title":"Today's Thesis Proposal","uri":"/todays-thesis-proposal/"},{"categories":["Journal"],"content":"The flour may be less, it’s not as good as last time. Not bad. ","date":"2022-03-04","objectID":"/made-a-cake-again/:0:0","tags":["cake"],"title":"Made a Cake Again🍰","uri":"/made-a-cake-again/"},{"categories":["Note"],"content":"LeetCode 42.Trapping Rain Water, a very interesting problem. Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example: Input: height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]. In this case, 6 units of rain water (blue section) are being trapped. At first I wanted to solve it with stack, but it didn’t feel good. Then I just calculated directly up and down, but Time Limit Exceeded: class Solution { public: int trap(vector\u003cint\u003e\u0026 height) { int ans = 0; unordered_map\u003cint, vector\u003cint\u003e\u003e index; for (int i = 0; i \u003c height.size(); ++i) { for (int j = 1; j \u003c= height[i]; ++j) index[j].push_back(i); } for (auto p : index) { auto v = p.second; for (int i = 1; i \u003c v.size(); ++i) ans += v[i] - v[i - 1] - 1; } return ans; } }; Read the reference solution and the main idea is to surround the left and right sides and find the height of the horizontal plane: class Solution { public: int trap(vector\u003cint\u003e\u0026 height) { int ans = 0, l = 0, r = height.size() - 1, level = 0; while (l \u003c r) { int lower = (height[l] \u003e height[r] ? height[r--] : height[l++]); level = max(lower, level); ans += level - lower; } return ans; } }; There should be many solutions to this problem. ","date":"2022-02-18","objectID":"/leetcode-42/:0:0","tags":["algorithms","C++","LeetCode"],"title":"LeetCode 42","uri":"/leetcode-42/"},{"categories":["Journal"],"content":"A few days ago, I went to Pingyao Ancient City. The entire ancient city preserves the original appearance of the Ming and Qing Dynasties. It’s very spectacular to gaze into the distance from the city wall. There are many snacks, my favorite is Pingyao beef and wantuo! ","date":"2022-02-13","objectID":"/pingyao-ancient-city/:0:0","tags":["stroll"],"title":"Pingyao Ancient City","uri":"/pingyao-ancient-city/"},{"categories":["Note"],"content":"A C++ template for the doubly linked list. #include \u003ciostream\u003e using namespace std; struct ListNode { int val; ListNode *next, *prior; ListNode() : val(0), next(nullptr), prior(nullptr) {} ListNode(int v) : val(v), next(nullptr), prior(nullptr) {} ListNode(int v, ListNode *next, ListNode *prior) : val(v), next(next), prior(prior) {} }; ListNode *insert(ListNode *p, int val) { ListNode *n = new ListNode; n-\u003eval = val; n-\u003enext = p-\u003enext; p-\u003enext = n; n-\u003eprior = p; if (n-\u003enext != nullptr) n-\u003enext-\u003eprior = n; return n; } void erase(ListNode *p) { p-\u003eprior-\u003enext = p-\u003enext; if (p-\u003enext != nullptr) p-\u003enext-\u003eprior = p-\u003eprior; delete p; } void print(ListNode *p) { if (p != nullptr) { cout \u003c\u003c p-\u003eval; p = p-\u003enext; } while (p != nullptr) { cout \u003c\u003c \" -\u003e \" \u003c\u003c p-\u003eval; p = p-\u003enext; } cout \u003c\u003c endl; } int main() { ListNode *front = new ListNode(1); ListNode *n = insert(insert(insert(front, 2), 4)-\u003eprior, 3); print(front); // 1 -\u003e 2 -\u003e 3 -\u003e 4 erase(n); print(front); // 1 -\u003e 2 -\u003e 4 return 0; } LeetCode 21. Merge Two Sorted Lists class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { if (list1 == nullptr \u0026\u0026 list2 == nullptr) return nullptr; else if (list1 == nullptr) return list2; else if (list2 == nullptr) return list1; else { ListNode *front, *p, *p1, *p2; if (list1-\u003eval \u003c= list2-\u003eval) { front = list1; p1 = list1-\u003enext; p2 = list2; } else { front = list2; p1 = list1; p2 = list2-\u003enext; } p = front; while (p1 != nullptr \u0026\u0026 p2 != nullptr) { if (p1-\u003eval \u003c= p2-\u003eval) { p-\u003enext = p1; p1 = p1-\u003enext; } else { p-\u003enext = p2; p2 = p2-\u003enext; } p = p-\u003enext; } if (p1 == nullptr) p-\u003enext = p2; else p-\u003enext = p1; return front; } } }; LeetCode 23. Merge k Sorted Lists Using this method directly resulted in Time Limit Exceeded, class Solution { public: ListNode *mergeKLists(vector\u003cListNode *\u003e \u0026lists) { int flag = 0, min = 0x3f3f3f; ListNode *front, *p, *p1; unordered_map\u003cListNode *, ListNode *\u003e ptr; vector\u003cListNode *\u003e ps; for (auto list : lists) { if (list != nullptr) { flag = 1; ptr[list] = list; if (list-\u003eval \u003c min) { min = list-\u003eval; front = list; } } } if (!lists.size() || !flag) return nullptr; else { ptr[front] = ptr[front]-\u003enext; p = front; while (true) { flag = 0, min = 0x3f3f3f; for (auto list : lists) { if (ptr[list] != nullptr) { flag = 1; if (ptr[list]-\u003eval \u003c min) { min = ptr[list]-\u003eval; p1 = list; } } } if (!flag) break; p-\u003enext = ptr[p1]; p = p-\u003enext; ptr[p1] = ptr[p1]-\u003enext; } return front; } } }; and I solved it using the priority queue. class Solution { public: ListNode *mergeKLists(vector\u003cListNode *\u003e \u0026lists) { ListNode *front, *p; auto cmp = [](ListNode *a, ListNode *b) { return a-\u003eval \u003e= b-\u003eval; }; // ptr.top() is minimal. priority_queue\u003cListNode *, vector\u003cListNode *\u003e, decltype(cmp)\u003e ptr(cmp); for (auto list : lists) { if (list != nullptr) ptr.push(list); } if (!lists.size() || ptr.empty()) return nullptr; else { front = ptr.top(); ptr.pop(); if (front-\u003enext != nullptr) ptr.push(front-\u003enext); p = front; while (!ptr.empty()) { p-\u003enext = ptr.top(); ptr.pop(); p = p-\u003enext; if (p-\u003enext != nullptr) ptr.push(p-\u003enext); } return front; } } }; ","date":"2022-01-31","objectID":"/linked-list/:0:0","tags":["linked list","priority queue","data structure","C++","LeetCode"],"title":"Linked List","uri":"/linked-list/"},{"categories":["Note"],"content":"This is a C++ template for the binary search algorithm, and a simple application of the binary search functions std::lower_bound and std::upper_bound in the C++ standard template library \u003calgorithm\u003e header file. #include \u003calgorithm\u003e #include \u003ciostream\u003e using namespace std; int nums[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int binary_search(int left, int right, int key) { int pos = -1, mid; while (left \u003c= right) { mid = left + (right - left) / 2; if (key \u003e nums[mid]) left = mid + 1; else if (key \u003c nums[mid]) right = mid - 1; else { pos = mid; break; } } return pos; } int main() { cout \u003c\u003c binary_search(0, 9, 3) \u003c\u003c endl; // 2 cout \u003c\u003c lower_bound(nums, nums + 10, 3) - nums \u003c\u003c endl; // 2, \u003e= 3 cout \u003c\u003c upper_bound(nums, nums + 10, 3) - nums \u003c\u003c endl; // 3, \u003e 3 return 0; } Used this template and completed 34. Find First and Last Position of Element in Sorted Array in LeetCode. class Solution { public: vector\u003cint\u003e searchRange(vector\u003cint\u003e\u0026 nums, int target) { if (!nums.size()) return vector\u003cint\u003e{-1, -1}; else { int pos = binary_search(nums, 0, nums.size() - 1, target); if (pos == -1) return vector\u003cint\u003e{-1, -1}; else { int left = pos - 1, right = pos + 1, size = nums.size(); while (left \u003e= 0 \u0026\u0026 nums[left] == target) --left; while (right \u003c size \u0026\u0026 nums[right] == target) ++right; return vector\u003cint\u003e{left + 1, right - 1}; } } } int binary_search(vector\u003cint\u003e nums, int left, int right, int key) { int pos = -1, mid; while (left \u003c= right) { mid = left + (right - left) / 2; if (key \u003e nums[mid]) left = mid + 1; else if (key \u003c nums[mid]) right = mid - 1; else { pos = mid; break; } } return pos; } }; ","date":"2022-01-29","objectID":"/binary-search/:0:0","tags":["search","algorithms","C++","LeetCode"],"title":"Binary Search","uri":"/binary-search/"},{"categories":["Journal"],"content":"Yummy! ","date":"2022-01-18","objectID":"/made-a-cake/:0:0","tags":["cake"],"title":"Made a Cake🍰","uri":"/made-a-cake/"},{"categories":["Journal"],"content":"I went out for a walk today and took some photos. The blue sky! Fantastic! Monument to the People’s Heroes (north) Monument to the People’s Heroes (south) Chairman Mao Zedong Memorial Hall The Great Hall of the People Xinhua Gate ","date":"2021-12-27","objectID":"/i-went-to-tiananmen-today/:0:0","tags":["stroll"],"title":"I Went to Tiananmen Today","uri":"/i-went-to-tiananmen-today/"},{"categories":["Note"],"content":"At present, my website has stabilized and entered the routine maintenance stage. Now let’s review how it was built. There are various guidelines on the Internet, and this article is mainly about my own experience, so I won’t involve those repeated details. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:0:0","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Beginning Two weeks ago, I saw someone using Github as a free cloud drive. I have seen someone take notes and blog in a repository. Suddenly, I wanted to have a place to write something to record myself. I searched for how to blog on Github, and then I found Github Pages. In short, it can automatically host static webpages for free, and it is more than enough to build a blog of my own. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:1:0","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Domain Github Pages is free, but its URLs all look like username.github.io, which feels not personalized enough. Fortunately, it supports custom domains, so I decided to buy one. The website hadn’t been built yet, but I bought it first. I heard that buying a domain in China requires real-name verification, and the verification takes several days. If I wait for the verification while building my website, it will save time. Finally, I bought kayak4665664.com. Tip Some domains look cheap when they are registered in the first year, but later renewals are more expensive than .com domain. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:1:1","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"username.github.io Created a new repository and set Pages settings. Github Pages uses Jekyll to transform plain text into static websites, so it will let you choose your Jekyll theme during the setup process. I even carefully compared those themes and chose the one that I thought was the best-looking. I soon discovered that these themes were too simple to meet my needs. Then I used git to clone the repository to the local. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:1:2","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Design I visited some others’ websites and initially determined that my website should have the functions of comments, visit count, and in-site search. In addition, I also wanted to add Baidu and Google Analytics and let them index my website. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:1:3","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Tool In addition to Jekyll, there are many tools for transforming plain text into static websites and blogs, such as the Hugo I use now. Since Github Pages uses Jekyll by default, I chose Jekyll. Jekyll is based on Ruby and can be installed with gem. I use macOS and Ruby is a built-in software. I directly executed gem install jekyll bundler to start installing Jekyll, Bundler, and their dependencies. During the installation, fatal error:'ruby/config.h' file not found appeared. I googled it and found that some people said the version of the built-in Ruby was too low, but others said that it was a problem with Xcode CommandLineTools. I installed a new Ruby with Homebrew directly. After installation, set the environment variables in the terminal, re-executed gem install jekyll bundler, and the installation was complete this time. Warning I also searched for how to clean up the cache and installed packages of the last gem install jekyll bundler, but I didn’t find it. I had to manually uninstall the installed packages and delete the directory where the cache was located. I felt that it was not cleaned up at all. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:1:4","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Jekyll ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:2:0","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Getting start Executed bundle exec jekyll serve in the workplace, and cannot load such file - webrick (LoadError) appeared. I googled it and then solved it with bundle add webrick. I previewed it locally and felt there were no problems. I prepared to push it to Github and test it with my mobile phone. But there was a problem, push did not work. Google didn’t find it, but Baidu found that it may be a problem with proxy. It was resolved after unseting the proxy settings of git. Browsing with my phone, the webpage was automatically adapted to the mobile interface. At this time, I found that this theme was too simple, and it didn’t even have a pagination. In the beginning, I was planning to implement it myself, but I thought that so many functions would have to be implemented one by one, and the workload was huge. I’d better find a theme with more complete functions. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:2:1","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Theme There are many Jekyll themes on the Internet and finally downloaded YAT. It has many functions. We can use Disqus and Gitment to comment. After downloading, I wanted to execute bundle exec jekyll serve to preview it, but the error Could not find gem 'jekyll-spaceship (~\u003e 0.2)' appeared. I solved it by setting the version to 0.2 when installing jekyll-spaceship by gem. Here I also found that the installation was stuck, but there was no error. Using the Activity Monitor, I saw that the Rcvd Bytes of Ruby have been increasing slowly, which should be a network problem in China. Googled it, then found a way on Ruby China to change the sources. The installation was successful after changing them. Executed bundle exec jekyll serve again and this time I previewed the new theme. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:2:2","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Personalizing According to our own needs, we can make personalized changes to the theme, such as titles, pictures, etc. I originally wanted to use Gitment, but I found that it can’t log in to the Github account. I took a look at its Issues and then found that the service should be stopped. So I can only use Disqus, I registered a Disqus account and turned on the comment function. In addition, I also used Bu Suanzi for website traffic statistics, which only requires two lines of code. Then I started to add some content. In the process of previewing the content, I gradually discovered some problems. The font of this theme was too small, and the contrast between the text and the background was low whether in light or dark mode. In short, I felt that reading it tortures my eyes. However, the font cannot be set in the configuration file. I can only modify the .scss files one by one, which is more troublesome. And its translation function called Google’s webpage translation interface, was almost unusable under the Chinese network, causing the webpage to become stuck. I directly deleted the translation-related part of the source code. In addition, Disqus cannot log in to the account under the Chinese network. After a test, only anonymous guest comments can be used. This is also a disadvantage. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:2:3","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Giving up After personalization, I felt that there was no problem. It suddenly occurred to me that the YAT theme also supports PlantUML, Mermaid, Mathjax, Vedio, Audio, etc. I should test it again. I directly used the author’s markdown files to test and found that these things were not displayed normally. I thought it was because I changed the source code. I directly cloned the author’s repository. After testing, I found that the same does not work. It seems that it is not a problem with my code modification. But I haven’t found the problem. Considering that there were other shortcomings in this theme, I chose to abandon it. I started looking for the subject again, this time more carefully. Finally, I found the LoveIt theme, which is what I use now. This is a theme based on Hugo, so Ruby was useless, I uninstalled it. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:2:4","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Hugo ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:3:0","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Getting start First used Homebrew to install Hugo, LoveIt recommends installing the extended version of Hugo, and the Hugo installed by Homebrew is the extended version. The directory structure of Hugo is still different from that of Jekyll, it took some time to get familiar with. LoveIt has a lot of configuration items, and we need to take a look at the document first. Approximately configured, executed hugo serve -e production --disableFastRender to preview. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:3:1","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Personalizing After that were personalized settings, as well as: Registered LeanCloud and Valine for comments and visit statistics Used https://realfavicongenerator.net to generate website icons Registered Gravartar Registered Algolia for site search Used node.js to execute npm install atomic-algolia to install atomic-algolia to automatically upload index files to Algolia Registered Mapbox During this period, I also found a problem. The custom 404 template could not be displayed in the local preview. Google found it: Info hugo server will not automatically load your custom 404.html file, but you can test the appearance of your custom “not found” page by navigating your browser to /404.html. ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:3:2","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"Extension The website was almost built. Executed hugo, and the /public directory would appear. Synchronized /public with our repository, and we can host the webpage to Github Pages. Then used atomic-algolia to upload the generated index file to Algolia. After these two steps, a website deployment was completed. In addition, I built a private repository for synchronizing source code other than /public, so every deployment needs to be synchronized once more. To automate these three processes, I wrote a Shell script. Only one step. At this time, my domain finally passed the real-name verification. I started to make some extensions: Set up CNAME on Github Imported the repository into Vercel, so that every time the repository is updated, it will be automatically deployed to Vercel. It is said that Baidu will not index sites hosted by Github Pages, and it can be indexed after being deployed to Vercel Set a custom domain in Vercel Added Baidu Tongji and Google Analytics Submitted the sitemap to Baidu Ziyuan and Google Search Console, in Bing Webmaster Tools directly imported the submitted sitemap into Google Search Console ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:3:3","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Note"],"content":"End In the future, I also plan to add a little Google advertisement, which is also a feature of most websites. In general, there are a lot of gains this time! ","date":"2021-12-22","objectID":"/how-my-wesite-was-built/:4:0","tags":["My Website","Github Pages","Github","Jekyll","Hugo"],"title":"How My Wesite Was Built?","uri":"/how-my-wesite-was-built/"},{"categories":["Journal"],"content":"Google has indexed my website! At present, I have also submitted the sitemap to Baidu and Bing, waiting to be indexed. Now my website is gradually getting on track, so I am going to write an article next week to review how my website was built. ","date":"2021-12-19","objectID":"/google-has-indexed-my-website/:0:0","tags":["My Website"],"title":"Google Has Indexed My Website","uri":"/google-has-indexed-my-website/"},{"categories":["Journal"],"content":"This week my school started the work on the graduation project, and now I have determined the topic and officially started my graduation project. ","date":"2021-12-18","objectID":"/graduation-project-starts-now/:0:0","tags":["graduation project","NCUT"],"title":"Graduation Project Starts Now","uri":"/graduation-project-starts-now/"},{"categories":["Journal"],"content":"Topic selection I already had a topic before, and a tutor in the group gave me a topic on the security of the Iots. I think this topic is quite suitable. On the one hand, I can understand some knowledge of the IoTs, and on the other hand, I have completed my final project, which can be regarded as killing two birds with one stone. ","date":"2021-12-18","objectID":"/graduation-project-starts-now/:1:0","tags":["graduation project","NCUT"],"title":"Graduation Project Starts Now","uri":"/graduation-project-starts-now/"},{"categories":["Journal"],"content":"Meeting After the mobilization meeting of the graduation project, I met with my adviser. He hosted a short meeting for us and talked a lot. It’s nothing. The only thing is that a WeCom group was created, and he became the “寨主 (zhàizhǔ, brigand chief)”. ","date":"2021-12-18","objectID":"/graduation-project-starts-now/:2:0","tags":["graduation project","NCUT"],"title":"Graduation Project Starts Now","uri":"/graduation-project-starts-now/"},{"categories":["Journal"],"content":"Report Although I selected a topic before, I still need to think about it seriously. After all, the graduation project is not so casual. My adviser posted some reference topics in the group, all of which are quite classic. However, that topic is very new to me. I have never worked in this field before. In general, I prefer the topic of Iots, and the tutor in the group also hopes that I will complete this topic very well. So I reported it to my adviser. ","date":"2021-12-18","objectID":"/graduation-project-starts-now/:3:0","tags":["graduation project","NCUT"],"title":"Graduation Project Starts Now","uri":"/graduation-project-starts-now/"},{"categories":["Journal"],"content":"Discussion What the adviser said: The 题目 (tímù, Which means “title” or “topic” in Chinese.) is incomplete. Write a complete one. Okay, I described my topic more completely, waiting for his opinion. The message has been read, but there has been no reply. It’s inexplicable, wouldn’t he forget it? The next day, I sent him a message and asked his opinion again, and suddenly received a 59-second voice message. What the adviser said: … Yous is not a 题目 at all, yours is just a spoken expression. How could that be a 题目? And the work you will do, to be honest, is too searchable. I can’t say… If I don’t see the specific content. Then what you do can be more or less. The requirements for you, I don’t know… If it’s low, it’s very simple and not too difficult; if it’s high, that’s a certain degree of difficulty, okay? Then you wrote so much, how could yours be a 题目? Yours is Just a Spoken Expression! Your spoken expression, how can I decide for you? You want to determine it, can I decide on a spoken expression for you? Can it be a 题目? You can’t write a 题目 yourself, you ask me to decide? Deciding a spoken expression for you, is appropriate? Ok? After you’ve thought about it yourself, we will have a basis for discussion. Otherwise, there is nothing to say! I was stunned, he said mine is not a topic. Regardless of whether it is a topic or not, if he thinks mine is not a topic and he has opinions or questions, couldn’t he tell me directly? I can modify or improve it! He keeps not replying, can I know what he thinks? I experienced this situation for the first time since I was born, and I didn’t know what it meant to me. I also told my master tutor about this matter. The first message she replied to was: Why? I also showed her the voice of my adviser, and she helped me determine a title. Here I suddenly discovered that there may be a misunderstanding. Does the “题目” mentioned by my adviser refer to the “title” or the “topic”? I checked the Modern Chinese Normative Dictionary, and “题目” does have multiple meanings. He said that my “题目” was a “spoken expression”, and it seemed that the “题目” mentioned by him refers to the “title”. If so, why didn’t he make it clear at the beginning that he was talking about a title? Well, he said that I can’t write a title myself, and there is no basis for discussion. Then I sent him the determined title, hoping for further discussion. However, he still has nothing to say. At that time, I felt that the “title” or “topic” may not be the key. I thought of him saying in the group, “from this class, the educational administration is going to start the graduation project management system”, “all through the system”, and “leave traces”. “Moreover”, “qualification for the Washington Accord is in progress”, and “advisers strictly control the quality of topics”. I thought it may not be easy for him to check the professional level and workload of this topic. After all, he is not researching Iots, and there should be no similar topics in the past. He has been difficult to conclude, so he has nothing to say. I told the tutor int the group what I thought, and she suggested that I explain it to him in more detail. Therefore, I wrote a document that was a bit like an opening report. I wrote out the specific tasks to be done, and also initially planned the time allocation for each task. I sent it to my adviser and asked him to express his opinions directly if he had any questions. Finally, my adviser started to discuss it with me. What the adviser said: You can submit it. ","date":"2021-12-18","objectID":"/graduation-project-starts-now/:4:0","tags":["graduation project","NCUT"],"title":"Graduation Project Starts Now","uri":"/graduation-project-starts-now/"},{"categories":["Journal"],"content":"End In any case, the topic has been determined, and now it’s time to complete the project. Info The graduation project has been completed, please see this blog: NCUT-Pot, the project has also been open source. ","date":"2021-12-18","objectID":"/graduation-project-starts-now/:5:0","tags":["graduation project","NCUT"],"title":"Graduation Project Starts Now","uri":"/graduation-project-starts-now/"},{"categories":null,"content":"kayak4665664 Hey, Nice to Meet You, You Found My Blog! I’m kayak4665664, a student of University of Chinese Academy of Sciences. ","date":"2021-12-13","objectID":"/about/:1:0","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"Help ","date":"2021-12-13","objectID":"/about/:2:0","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"1. How to subscribe to the blog? First you should install an RSS reader, and then click to add the RSS link to your reader. If you don’t want to install an RSS reader, you can also: Add Bookmark Add to Home Screen ","date":"2021-12-13","objectID":"/about/:2:1","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"2. How to comment on this site? Just enter your comment and click Submit. You can also enter your nickname, email and website. If you enter a Gravtar email address, your avatar can be displayed. ","date":"2021-12-13","objectID":"/about/:2:2","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"License All content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. ","date":"2021-12-13","objectID":"/about/:3:0","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"You are free to: Share — copy and redistribute the material in any medium or format Adapt — remix, transform, and build upon the material The licensor cannot revoke these freedoms as long as you follow the license terms. ","date":"2021-12-13","objectID":"/about/:3:1","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"Under the following terms: Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. NonCommercial — You may not use the material for commercial purposes. ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. ","date":"2021-12-13","objectID":"/about/:3:2","tags":null,"title":"About","uri":"/about/"},{"categories":null,"content":"Notices: You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation. No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material. ","date":"2021-12-13","objectID":"/about/:3:3","tags":null,"title":"About","uri":"/about/"},{"categories":["Journal"],"content":"Hello World! ","date":"2021-12-12","objectID":"/hello-world/:1:0","tags":["My Website"],"title":"Hello World!","uri":"/hello-world/"},{"categories":null,"content":"Offline - kayak4665664","date":"0001-01-01","objectID":"/offline/","tags":null,"title":"","uri":"/offline/"}]