题目: 给定一组单词,找出其中的最长单词,且该单词由这组单词中的其他单词组成。 思路: 首选将单词按照字符串大小从大到小排序,然后依次判断该单词是否由其他单词组成。 将单词保存在散列表中,这样容易查找。 判断单词组成:依…
(算法)Binary Tree Max Path Sum
题目: Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nod…
(算法)Word Break
题目: Given a string s and a dictionary of words dict, determine if s can be segmented …
(算法)成都麻将
题目: 说起麻将,那可是川渝市民的最爱,无论亲朋好友聚会,还是业务谈判,总是少不了麻将的声音。成都麻将只能包括3种类型:条,筒,万。没有“门、东南西北、红中”。每种牌都是数字从1到9,每个数字有4张,共36张。筒,万,条…
(算法)判断字符串中是否包含HelloWorld
题目: 给定某字符串,判断该字符串中是否包含HelloWorld,出现HelloWorld不一定要连续,但顺序不变,如“HeByello,ByeWorByeld”就包含“HelloWorld”。 思路: 通过i,j来遍历…
(算法)Game
题目: Jeff loves playing games, Gluttonous snake( an old game in&nb…
(算法)Word Break
题目: Given a string s and a dictionary of words dict, determine if s can be segmented …
(算法)格雷码
题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-n…
(算法)二叉树中两个结点的最近公共父结点
题目: 二叉树中两个结点的最近公共父结点 二叉树结点的定义如下: struct TreeNode{ int val; TreeNode *left; TreeNode *right; }; 思路: 前面在剑指…
(算法)Game
题目: Jeff loves playing games, Gluttonous snake( an old game in&nb…
(笔试题)最小的非“重复的数”
题目: 给一个定义:对一个整数,若其中存在相邻两位上的数字相同,则称其为“重复的数”;现给定一个正整数n,求不小于n的最小的非“重复的数”。 思路: 假设输入的数为n,则令m=n, 分别取m的最低两位数字a,b, 判断是…
(剑指Offer)面试题59:对称的二叉树
题目: 请实现一个函数,用来判断一颗二叉树是不是对称的。 注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。 思路: 对于一棵二叉树,从根结点开始遍历, 如果左右子结点有一个为NULL,那么肯定不是对称二叉树…