摘要:
Invert a binary tree. Example: Input: Output: 题目大意: 翻转一个二叉树的左右子树。 理 解: 若当前子树为空,则返回空树;若当前子树为孤节点,则返回该节点。 递归获得根节点左右子树。交换根节点的左右子树。 代 码 C++: 运行结果: 执行用时 :4 阅读全文
摘要:
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the 阅读全文
摘要:
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr 阅读全文
摘要:
Reverse a singly linked list. Example: 题目大意: 逆置链表。 理 解: 比较简单。注意头节点的变化。 代 码 C++: 运行结果: 执行用时 :8 ms, 在所有C++提交中击败了99.68%的用户 内存消耗 :9.3 MB, 在所有C++提交中击败了8.64 阅读全文
摘要:
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc 阅读全文
摘要:
Count the number of prime numbers less than a non-negative number, n. Example: 题目大意: 求所有小于非负整数n的质数的数量。 理 解: 最直接的做法就是求每个数i 是否有2到 i-1间的因子。统计质数个数。但该方法时间复 阅读全文
摘要:
Remove all elements from a linked list of integers that have value val. Example: 题目大意: 删除链表中等于给定元素值的节点。 理 解: 很简单,注意头节点位置即可。找到第一个非给定元素值的节点作为头节点,再向后遍历删除 阅读全文
摘要:
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege 阅读全文
摘要:
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo 阅读全文