LeetCode
likewind1993
专注在线推理,高性能计算方向;做对的事情,坚持
展开
-
LeetCode 720. Longest Word In Dictionary
原题: Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there is more than one possi原创 2017-11-05 15:15:09 · 1114 阅读 · 0 评论 -
LeetCode 1002. Find Common Character
原题 Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs...原创 2019-03-03 20:07:13 · 1772 阅读 · 0 评论 -
Leetcode 996. Number of Squareful Arrays
原题 Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square. Return the number of permutations of A that are squareful. ...原创 2019-02-20 18:29:08 · 337 阅读 · 0 评论 -
LeetCode 1001. Grid Illumination
原题 On a N x N grid of cells, each cell (x, y) with 0 <= x < N and 0 <= y < N has a lamp. Initially, some number of lamps are on. lamps[i] tells us the location of the i-th lamp that is on...原创 2019-02-28 09:46:40 · 458 阅读 · 0 评论 -
Leetcode 995. Minimum Number of K Consecutive Bit Flips
原题 In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray ...原创 2019-02-23 14:19:36 · 817 阅读 · 0 评论 -
Leetcode 968. Binary Tree Cameras
原题 Given a binary tree, we install cameras on the nodes of the tree. Each camera at a node can monitor its parent, itself, and its immediate children. Calculate the minimum number of cameras needed to...原创 2019-01-01 15:35:00 · 986 阅读 · 0 评论 -
刷Leetcode中用到的Code Fragment
前言 刷leetcode的时候,一方面考察的是自己的思路,另一方面更多的考察对已有库的运用(如string, map等),因此不可避免的会有很多重复造轮子的工作,这里总结下经常用到的代码片段(Code Fragment)。这样以后刷题遇到相似的类型的可以直接复制过来用,减少重复的东西。 二叉树 这里主要是节点的定义,以及构造树的结构,可以用来调试 树的构造 //树节点的定义 struct Tree...原创 2018-12-31 09:59:33 · 330 阅读 · 1 评论 -
leetcode Weekly Contest 112
前言 leetcode 每周末都会举行编程比赛,一共四道题,虽然都有参加,但是水平依然有限,不过参加比赛的一个好处就是可以在比赛后review别人的解答,是一个非常棒的学习材料,因为可以从别人的解答里发现高手的蛛丝马迹。 leetcode 937.Reorder Log Files 思路 主要是对输入的字符串进行排序,其中数字型log按照原次序输出,因此想法,字符型log需要按照字典序进行排列,然...原创 2018-11-30 21:13:19 · 247 阅读 · 0 评论 -
已知二叉树的先序排列和中序排列,重构该二叉树,并输出该树的后序遍历
前言 好久没写算法题,第一次碰到居然懵了,心里想着用递归用递归,却怎么也想不出思路来。 实现 思路 举例: 前序遍历为:1 2 4 5 3 6 7 中序遍历为:4 2 5 1 6 3 7 我们可以由先序遍历的顺序得到二叉树中节点的顺序,如从1开始,这样在中序遍历中找到1的位置的时候,在1左边的即为1节点的左子树元素(4 2 5 ),在1右边的即为1节点的右子树元素(...原创 2018-03-13 19:39:43 · 1424 阅读 · 0 评论 -
LeetCode 721. Accounts Merge
原题Given a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.Now,原创 2017-11-07 22:22:48 · 3139 阅读 · 1 评论 -
LeetCode 23. Merge k Sorted Lists
原题 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4-...原创 2019-03-24 10:21:20 · 135 阅读 · 0 评论