摘要: Sort a linked list in O(n log n) time using constant space complexity. Example 1: Example 2: 使用归并排序 阅读全文
posted @ 2019-08-06 21:35 月半榨菜 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. E 阅读全文
posted @ 2019-08-06 21:15 月半榨菜 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, two is written as II in Roman numeral, just two one's 阅读全文
posted @ 2019-08-05 15:24 月半榨菜 阅读(99) 评论(0) 推荐(0) 编辑
摘要: Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the vali 阅读全文
posted @ 2019-08-05 14:33 月半榨菜 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 小易参加了一个骰子游戏,这个游戏需要同时投掷n个骰子,每个骰子都是一个印有数字1~6的均匀正方体。小易同时投掷出这n个骰子,如果这n个骰子向上面的数字之和大于等于x,小易就会获得游戏奖励。小易想让你帮他算算他获得奖励的概率有多大。 阅读全文
posted @ 2019-08-01 17:28 月半榨菜 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为牛客的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个大圈。然后,他随机指定一个数m,让编号为0的小朋友开始报数。每次喊到m-1的那个小朋友要出列唱首歌,然后可以在礼品箱中任意的挑选礼 阅读全文
posted @ 2019-08-01 16:25 月半榨菜 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。 正则表达式 阅读全文
posted @ 2019-08-01 15:07 月半榨菜 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但是与"aa.a"和"ab*a"均不匹配。 阅读全文
posted @ 2019-08-01 14:37 月半榨菜 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 请实现两个函数,分别用来序列化和反序列化二叉树。 前序遍历 还可用层次遍历 阅读全文
posted @ 2019-08-01 11:03 月半榨菜 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 题目描述 将一个字符串转换成一个整数(实现Integer.valueOf(string)的功能,但是string不符合数字要求时返回0),要求不能使用字符串转换整数的库函数。 数值为0或者字符串不是一个合法的数值则返回0。 输入一个字符串,包括数字字母符号,可以为空 如果是合法的数值表达则返回该数字 阅读全文
posted @ 2019-07-31 22:10 月半榨菜 阅读(191) 评论(0) 推荐(0) 编辑