Skip to content

Instantly share code, notes, and snippets.

View JChehe's full-sized avatar

J.c JChehe

View GitHub Profile
@JChehe
JChehe / getHorizontalInfoThroughPixels.js
Created November 14, 2018 13:18
canvas 遍历像素获取像素区域(实际内容)的尺寸
function getHorizontalInfoThroughPixels (ctx) {
const canvas = ctx.canvas
const width = canvas.width
const height = canvas.height
const data = ctx.getImageData(0, 0, width, height).data
let firstCol = 0
let lastCol = 0
let isFindLastCol = false
let isFindFirstCol = false
@JChehe
JChehe / validBrackets.js
Created November 14, 2018 13:07
括号配对算法
/*
* 实现思路:
* 1. 创建一个栈
* 2. 遍历字符串
* - 栈为空时,若 item 为左括号则入栈,右括号则 return false
* - item 为左括号就入栈
* - item 为右括号时,stack 就 pop 出左括号,判断两者是否匹配
* - 若匹配则继续
* - 若不匹配则 return false
*/