题目描述: 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…
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…