LeetCode之旅(22)-House Robber】的更多相关文章

题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. Subscribe to see which companies asked this question Show Tags Show Similar Problems 准备知识看上篇博客 leetcode之旅(10)-Roman to Integer 思路: 当前这个数…
题目介绍: Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume the string con…
题目: 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 you from robbing each of them is that adjacent houses have security system connected and it will a…
House Robber题目链接 House Robber II题目链接 1. House Robber 题目要求: 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 you from robbing each of them is that adjac…
题目 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 integer, replace the number by the sum of the squares of its digits, and repeat the process until…
Total Accepted: 1341 Total Submissions: 3744 Difficulty: Medium The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent…
在此记录一下用javascript刷leetcode的过程,每天都要坚持! 1.Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where in…
网络通信的作用不用多说,而这次进行的工作即是对以太网通信过程中,需要用到的硬件部分进行初始化,也介绍了发送和接收数据的方法. 由于较为复杂,所以使用了ASF框架.但是也会对用到的库函数的实现做一个介绍. 一. MAC.PHY和MII IEEE 802.3是现在常用的以太网标准,它定义了物理层(Physical Layer, PHY)和介质访问控制层(Media Access Control, MAC)的标准.另外,在OSI模型中,MAC则处于数据链路层的底层. 而在硬件实现上,M4使用的GMAC…
class Solution(object):    def rob(self, nums):        """        :type nums: List[int]        :rtype: int        """        n=len(nums)        if n==0:            return 0        if n==1:            return nums[0]        i=2…
66. Plus One 题目 这题很简单,直接代码: class Solution { public: vector<int> plusOne(vector<int> &digits) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. ; vector<int>…
背景描述 Homebrew 是 OS X 平台上的包管理工具.用其官网的话说就是: the missing package manager for OS X | OS X 平台遗失的包管理器. 相信在用 Mac 的程序员,差不多都知道 Homebrew. Homebrew 的开发者是 Max Howell.今天 Max 在推特发帖: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't…
题目描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Subscribe to see which companies asked this question 预备知识: 记数方法 基本字符 I V X L C D M 相应的阿拉伯数字表示为 1 5 10 50 100 500 1000 1.相同的数字连写,所表示的数等于这…
题目描述: Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? Subscribe to see which companies asked this question 分析: 注意这个数据结构,这是一个链表,要求颠倒顺序.考虑设置两个变量,来表…
题目: 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 array, and it should return false if every element is distinct. Subscribe to see which companies as…
Move Zeroes 题目描述: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12,…
题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it withou…
题目介绍 You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remo…
题目: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list…
题目: Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 思路: 这个问题是求一个数是不是3的次方数,可以有两种解法: 1.采用余数的算法 2.利用了java 的对数运算,判断3的对象是否实在整数,其中用到了换底公式 代码1 public class Solution {…
题目 Given an integer, write a function to determine if it is a power of two. Credits: Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases. 思路 判断一个整数,是不是的2的次方数 ,利用对2求余,来循环除以2,看最后是不是1 代码: public class Solution { pu…
题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 i…
题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 先验知识: 斐波那契数列 斐波那契数列(Fibonacci sequence),又称黄金分割数列.因数学家列昂纳多·斐波那契(Leonardoda Fibo…
题目描述: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. # You should try to do it in place. The program should run in O(1) space…
题目描述: Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). For example, the 32-bit integer '11' has binary representation 00000000000000000000000000001011, so the function shoul…
14. 最长公共前缀 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow","flight"] 输出: "fl" 示例 2: 输入: ["dog","racecar","car"] 输出: "" 解释: 输入不存在公共前缀. 说明: 所有输…
思路: 递归解决,如果左括号个数小于右括号或者左括号数小于总括号对数,则生成一个左括号,如果左括号数大于右括号,生成一个右括号. class Solution { public: vector<string> ans; int num; void brackets(string res, int left, int right, int sum) { * num) { ans.push_back(res); } else{ , right, sum + ); , sum + ); } } ve…
1. 532. K-diff Pairs in an Array 分析:由于要唯一,所以要去重,考虑k=0,时候,相同的数字需要个数大于1,所以,先用map统计个数,对于k=0,特判,对于其他的,遍历每一个数,只需要判断a + k是否存在即可. 这个题目,是absolute difference,我没注意这点,没有判断k<0,直接return 0,导致出错. class Solution { public: int findPairs(vector<int>& nums, int…
打家劫舍 题目描述 你是一个专业的小偷,计划偷窃沿街的房屋.每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警. 给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报装置的情况下,能够偷窃到的最高金额. 示例 1: 输入: [1,2,3,1] 输出: 4 解释: 偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3).   偷窃到的最高金额 = 1 + 3 = 4 . 示例…
题目链接:https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/ 输入一个链表,输出该链表中倒数第k个节点.为了符合大多数人的习惯,本题从1开始计数,即链表的尾节点是倒数第1个节点.例如,一个链表有6个节点,从头节点开始,它们的值依次是1.2.3.4.5.6.这个链表的倒数第3个节点是值为4的节点. 示例: 给定一个链表: 1->2->3->4->5, 和 k = 2. 返回链表…
题目:给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标.你可以假设每种输入只会对应一个答案.但是,数组中同一个元素不能使用两遍. 示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1] 代码: class Solution: def twoSum(self, nums: List[int], target: int…