上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 26 下一页
摘要: 给定一个模板,和一个字符串,判断字符串中的单词是否如模板那样排列。Input: pattern = "abba", str = "dog cat cat dog"Output: true 难点:这是双射的,需要考虑 pattern -> str;也需要考虑 str -> pattern ,这样才是 阅读全文
posted @ 2020-05-14 16:44 星海寻梦233 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 给定一个数组,将数组中的0全部移到数组的末尾,同时保持非0元素的相对顺序不变。Input: [0,1,0,3,12]Output: [1,3,12,0,0] 思路:题目要求不要用到复制数组,所以只能使用交换的方法,且要尽可能少的操作总数。运用2个下标 i, j ,下标 i 记录遍历数组的下标,当遍历 阅读全文
posted @ 2020-05-14 15:16 星海寻梦233 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 有一系列产品的版本,如果其中一个版本错了,则在它之后的都错了。调用API函数 isBadVersion( )找到错误开始的源头,要求尽量少的调用API。Given n = 5, and version = 4 is the first bad version. call isBadVersion(3 阅读全文
posted @ 2020-05-13 23:51 星海寻梦233 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 给定一个数组,包含0,1,2…….n 的 n个数,输出缺失的那一个。Input: [9,6,4,2,3,5,7,0,1]Output: 8 思路:因为 0 ~ n 共有 n+1个数,而给定的数组中只有 n 个数,n 取决于数组的长度;所以,不管如何,都缺失一个数,偏一点的例子,如: [0,1],则缺 阅读全文
posted @ 2020-05-13 22:47 星海寻梦233 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 给定一个数,判断其质因数是否是2,3,5。Input: 6Output: trueExplanation: 6 = 2 × 3 Input: 14Output: false Explanation: 14 is not ugly since it includes another prime fac 阅读全文
posted @ 2020-05-13 21:25 星海寻梦233 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数,求每个数位上的数字之和,若结果大于10,则继续相加,直到其结果小于10.Input: 38Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, ret 阅读全文
posted @ 2020-05-13 21:04 星海寻梦233 阅读(93) 评论(0) 推荐(0) 编辑
摘要: Given two strings s and t , write a function to determine if t is an anagram of s.Input: s = "anagram", t = "nagaram"Output: true 难点:没读懂题意,开始以为是映射,提交好 阅读全文
posted @ 2020-05-12 22:50 星海寻梦233 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 给定一个单链表中的节点,将这个节点删除。Input: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You are given the second node with value 5, the linked list should be 阅读全文
posted @ 2020-05-12 21:58 星海寻梦233 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 给定一个二叉搜索树,以及2个节点p, q ,求这两个节点的最近公共祖先。 Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8Output: 6Explanation: The LCA of nodes 2 and 8 is 6. Inp 阅读全文
posted @ 2020-05-12 20:39 星海寻梦233 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 给定一个单链表,求其是否可回读,即,正着读和倒着读一样。Input: 1->2->2->1Output: true 思路:一、遍历链表,将其节点的值存入动态数组中,最后对数组头尾的值遍历判别。 bool isPalindrome(ListNode* head) { vector<int> tmp; 阅读全文
posted @ 2020-05-12 16:06 星海寻梦233 阅读(93) 评论(0) 推荐(0) 编辑
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 26 下一页