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

摘要:给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 例如,121 是回文,而 123 不是。 示例 1: 输入:x = 121 输出:true 示例 2: 输入:x = -121 输出:false 阅读全文
posted @ 2022-09-13 13:59 六层楼 阅读(26) 评论(0) 推荐(0) 编辑
摘要:一、爬楼梯 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数。 示例 1: 输入: 2 输出: 2 解释: 有两种方法可以爬到楼顶。 1 阶 + 1 阶 2 阶 示例 2: 输入: 3 输出: 3 解 阅读全文
posted @ 2021-07-13 16:43 六层楼 阅读(176) 评论(0) 推荐(0) 编辑
摘要:游戏币组合 ⼩明的抽屉⾥有n个游戏币,总⾯值m,游戏币的设置有1分的,2分的,5分的,10分的,⽽在⼩明 所拥有的游戏币中有些⾯值的游戏币可能没有,求⼀共有多少种可能的游戏币组合⽅式? 输⼊:输⼊两个数n(游戏币的个数),m(总⾯值)。 输出:请输出可能的组合⽅式数; 解题思路 暴力求解显然是一种能 阅读全文
posted @ 2020-10-09 17:32 六层楼 阅读(1527) 评论(0) 推荐(0) 编辑
摘要:部门优化 某公司内有 4 个项⽬组,项⽬组 A、B、C、D,项⽬组A现有10人,项⽬组B现有7人,项⽬组C现 有5人,项⽬组D现有4人。为了实现跨项⽬组协作,公司决定每⽉从⼈数最多的项⽬组中抽调 3 ⼈ 出来,到其他剩下 3 组中,每组 1 人,这称之为一次调整优化(亦即经过第⼀次调整后,A组有7 阅读全文
posted @ 2020-10-09 17:31 六层楼 阅读(924) 评论(0) 推荐(0) 编辑
摘要:Comming soon 阅读全文
posted @ 2020-08-31 17:31 六层楼 阅读(203) 评论(0) 推荐(0) 编辑
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g 阅读全文
posted @ 2019-10-21 14:38 六层楼 阅读(159) 评论(0) 推荐(0) 编辑
摘要:最近公司的项目中,有个树形结构变图结构的问题。本来我们对项目中实体之间的关系是按树形结构来表示的,也就是说实体之间不会重用,也不会有环。现在我们需要变成图的结构,实体之间可以重用,但不能有环。那么该如何解决这个问题呢? 我们先定义出什么是环: 环定义:从一条边出发,如果能回到当前边则证明有环。 可见 阅读全文
posted @ 2019-07-16 17:29 六层楼 阅读(3505) 评论(5) 推荐(0) 编辑
摘要:Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the 阅读全文
posted @ 2019-02-05 22:44 六层楼 阅读(281) 评论(0) 推荐(0) 编辑
摘要:You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in Sis a type of stone 阅读全文
posted @ 2018-05-17 17:36 六层楼 阅读(202) 评论(0) 推荐(0) 编辑
摘要:本文整理自漫画: "什么是ConcurrentHashMap? 小灰的文章 知乎" 。已获得作者授权。 HashMap 在高并发下会出现链表环,从而导致程序出现死循环。高并发下避免HashMap 出问题的方法有两种。一是使用HashTable,二是使用Collections.syncronizedM 阅读全文
posted @ 2017-12-27 07:06 六层楼 阅读(2085) 评论(0) 推荐(0) 编辑
摘要:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. Th 阅读全文
posted @ 2017-12-08 10:05 六层楼 阅读(326) 评论(0) 推荐(0) 编辑
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given , the answer is , which the length is 3. Given 阅读全文
posted @ 2017-11-28 11:16 六层楼 阅读(150) 评论(0) 推荐(0) 编辑
摘要:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: Example 1: Exa 阅读全文
posted @ 2017-07-04 17:02 六层楼 阅读(462) 评论(0) 推荐(0) 编辑
摘要:与树的前中后序遍历的DFS思想不同,层次遍历用到的是BFS思想。一般DFS用递归去实现(也可以用栈实现),BFS需要用队列去实现。 层次遍历的步骤是: 1.对于不为空的结点,先把该结点加入到队列中 2.从队中拿出结点,如果该结点的左右结点不为空,就分别把左右结点加入到队列中 3.重复以上操作直到队列 阅读全文
posted @ 2017-07-03 09:22 六层楼 阅读(15158) 评论(2) 推荐(0) 编辑
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return ["2 阅读全文
posted @ 2017-03-23 16:10 六层楼 阅读(224) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2015-11-26 21:44 六层楼 阅读(169) 评论(0) 推荐(0) 编辑
摘要:Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solv... 阅读全文
posted @ 2015-10-18 13:34 六层楼 阅读(713) 评论(0) 推荐(0) 编辑
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-10-08 22:30 六层楼 阅读(154) 评论(0) 推荐(0) 编辑
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis... 阅读全文
posted @ 2015-10-06 18:53 六层楼 阅读(154) 评论(0) 推荐(0) 编辑
摘要:Total Accepted:83663Total Submissions:200541Difficulty:EasyGiven two binary trees, write a function to check if they are equal or not.Two binary trees... 阅读全文
posted @ 2015-10-03 20:55 六层楼 阅读(178) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示