随笔分类 -  数据结构与算法

摘要:完全原创,能力有限,欢迎参考,未经允许,请勿转载 ! 完全原创,能力有限,欢迎参考,未经允许,请勿转载 ! 完全原创,能力有限,欢迎参考,未经允许,请勿转载 ! 完全原创,能力有限,欢迎参考,未经允许,请勿转载 ! 阅读全文
posted @ 2017-11-03 22:00 稀里糊涂林老冷 阅读(7021) 评论(0) 推荐(0)
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文
posted @ 2017-09-24 19:29 稀里糊涂林老冷 阅读(186) 评论(0) 推荐(0)
摘要:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanation:The avera... 阅读全文
posted @ 2017-09-20 21:59 稀里糊涂林老冷 阅读(198) 评论(0) 推荐(0)
摘要:Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was added in... 阅读全文
posted @ 2017-09-18 10:19 稀里糊涂林老冷 阅读(240) 评论(0) 推荐(0)
摘要:我的思想是这样的: 要求是全灭了 就赢了。。那最左边如果有亮的 早晚都要解决。 我想 从左到右解决。选择第一个亮的,然后其他反过来。再选择第二个亮的其他反过来。 她俩一人选一次,所以组后执行次数如果是偶数就是bob赢了 如果是奇数就是alice赢了。 为了降低时间复杂度,我考虑: 第一次选择第一个1 阅读全文
posted @ 2017-09-14 21:07 稀里糊涂林老冷 阅读(372) 评论(0) 推荐(0)
摘要:这是我遇到的一道校招题目: 给定一字符串只包含数字,请写一个算法,找出该字符串中的最长不重复子串(不重复是指子串中每一元素不同于子串中其他元素) 如: “120135435”最长不重复子串为 "201354" 要求用java或者c来写,我用了java。 /** * 思想: * 从头开始截取字符串,只 阅读全文
posted @ 2017-09-10 19:04 稀里糊涂林老冷 阅读(716) 评论(0) 推荐(0)
摘要:最近在笔试的时候遇到碰一道算法题, 要求判断一个字符串是不是合法的ip地址。 将我的思路发出来分享一下,不一定正确,也不一定是最优的方法。希望能分享一些交流 要求用java或者c来实现,我的java代码: 阅读全文
posted @ 2017-09-10 19:01 稀里糊涂林老冷 阅读(11337) 评论(0) 推荐(0)
摘要:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the resul... 阅读全文
posted @ 2017-09-10 18:57 稀里糊涂林老冷 阅读(263) 评论(0) 推荐(0)
摘要:In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dimensi... 阅读全文
posted @ 2017-09-10 18:40 稀里糊涂林老冷 阅读(297) 评论(0) 推荐(0)
摘要:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.Th... 阅读全文
posted @ 2017-09-10 18:25 稀里糊涂林老冷 阅读(216) 评论(0) 推荐(0)
摘要:Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.American keyboardExample 1:Input: ["Hello", "Alaska", "D... 阅读全文
posted @ 2017-09-10 18:14 稀里糊涂林老冷 阅读(229) 评论(0) 推荐(0)
摘要:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely ... 阅读全文
posted @ 2017-09-10 18:09 稀里糊涂林老冷 阅读(320) 评论(0) 推荐(0)
摘要:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these... 阅读全文
posted @ 2017-09-10 18:04 稀里糊涂林老冷 阅读(256) 评论(0) 推荐(0)
摘要:leetcode算法: Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 ... 阅读全文
posted @ 2017-09-10 17:32 稀里糊涂林老冷 阅读(287) 评论(0) 推荐(0)
摘要:输入n * m 的二维数组 表示一个迷宫数字0表示障碍 1表示能通行移动到相邻单元格用1步思路:深度优先遍历,到达每一个点,记录从起点到达每一个点的最短步数初始化案例: 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1... 阅读全文
posted @ 2017-08-13 23:10 稀里糊涂林老冷 阅读(588) 评论(0) 推荐(0)
摘要:实现一个功能: 输入:一颗二叉树的先序和中序遍历 输出:后续遍历思想: 先序遍历中,第一个元素是树根 在中序遍历中找到树根,左边的是左子树 右边的是右子树 1 def fromFMtoL( mid ): 2 global las #全局后序遍历 3 global fir #先序遍历 4 5 root = fir[0] #取出... 阅读全文
posted @ 2017-08-13 23:07 稀里糊涂林老冷 阅读(1142) 评论(0) 推荐(0)
摘要:一个n*n个方块的图,每个方块是白色或者黑色。统计出相连的黑色块区域有多少个 相连:两个黑色块有公共顶点或者公共边输入0代表白色 1代表黑色 测试用例: 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 ... 阅读全文
posted @ 2017-08-13 23:05 稀里糊涂林老冷 阅读(907) 评论(0) 推荐(0)
摘要:最近在赛码网上做算法题,看到这样一道题,经过不断的学习,最后解决了。把我的思想和代码给大家分享一下~ 认老乡 题目描述大学的同学来自全国各地,对于远离家乡步入陌生大学校园的大一新生来说,碰到老乡是多么激动的一件事,于是大家都热衷于问身边的同学是否与自己同乡,来自新疆的小赛尤其热衷。但是大家都不告诉小 阅读全文
posted @ 2017-08-12 22:50 稀里糊涂林老冷 阅读(1520) 评论(0) 推荐(0)
摘要:格子游戏 题目描述 有n个格子,从左到右放成一排,编号为1-n。共有m次操作,有3种操作类型:1.修改一个格子的权值,2.求连续一段格子权值和,3.求连续一段格子的最大值。对于每个2、3操作输出你所求出的结果。 输入输入第一行两个整数,n表示格子个数... 阅读全文
posted @ 2017-08-12 22:09 稀里糊涂林老冷 阅读(1024) 评论(0) 推荐(0)
摘要:作为一名软件工程的本科生,满怀热情的投了各大公司的简历。 今天早上兴致勃勃的做了阿里巴巴后端开发的第一道预热题。 经过一番挣扎,我觉着,题目出的不够严谨,并且测试用例也出现错误了。 题目描述如下。 幼儿园有10个小朋友,把1 – 20中所有奇数数字的卡片分别发给这20个小朋友。集合的时候小朋友们排成 阅读全文
posted @ 2017-08-12 10:09 稀里糊涂林老冷 阅读(1353) 评论(8) 推荐(0)