摘要: 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) 编辑
摘要: 用栈实现队列的功能。MyQueue queue = new MyQueue(); queue.push(1);queue.push(2); queue.peek(); // returns 1queue.pop(); // returns 1queue.empty(); // returns fal 阅读全文
posted @ 2020-05-12 15:34 星海寻梦233 阅读(83) 评论(0) 推荐(0) 编辑