
Leetcode
小白笑苍
沉默是一种生活方式。
展开
-
319. Bulb Switcher
题目There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or turning off原创 2017-02-27 22:19:12 · 211 阅读 · 0 评论 -
150. Evaluate Reverse Polish Notation
题目Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: [“2”, “1”, “+”, “3”, “原创 2017-02-17 21:43:00 · 173 阅读 · 0 评论 -
153. Find Minimum in Rotated Sorted Array
题目Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exi原创 2017-02-17 23:20:22 · 236 阅读 · 0 评论 -
326. Power of Three
题目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?Credits: Special thanks to @dietpepsi for adding this problem原创 2017-02-27 22:54:11 · 247 阅读 · 0 评论 -
328. Odd Even Linked List
题目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 pl原创 2017-02-27 23:07:10 · 202 阅读 · 0 评论 -
329. Longest Increasing Path in a Matrix
题目Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of原创 2017-02-27 23:39:57 · 226 阅读 · 0 评论 -
338. Counting Bits
题目Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you原创 2017-02-27 23:58:50 · 195 阅读 · 0 评论 -
342. Power of Four
题目Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example: Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without loops/原创 2017-02-28 00:10:53 · 344 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
题目Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2017-02-18 19:52:37 · 422 阅读 · 0 评论 -
168. Excel Sheet Column Title
题目Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB Credits: Special thanks to @ifanchu for ad原创 2017-02-18 23:49:19 · 284 阅读 · 0 评论 -
169. Majority Element
题目Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alway原创 2017-02-18 23:55:36 · 190 阅读 · 0 评论 -
198. 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 adjacent hous原创 2017-02-19 18:27:47 · 218 阅读 · 0 评论 -
202. Happy Number
题目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原创 2017-02-19 18:37:19 · 182 阅读 · 0 评论 -
203. Remove Linked List Elements
题目Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5Credits: Special thanks to @mithmatt for原创 2017-02-19 18:44:09 · 254 阅读 · 0 评论 -
204. Count Primes
题目Description:Count the number of prime numbers less than a non-negative number, n.Credits: Special thanks to @mithmatt for adding this problem and creating all test cases.思路普通的计算素数个数效率太低,这里用空间换时间,搞一个原创 2017-02-19 18:54:26 · 148 阅读 · 0 评论 -
206. Reverse Linked List
题目Reverse a singly linked list.click to show more hints.Subscribe to see which companies asked this question.Show Tags Show Similar Problems思路两个指针一前一后遍历翻转链表指向,注意最后要把最开始的head的next指针弄成NULL代码/** * Defin原创 2017-02-19 22:25:46 · 253 阅读 · 0 评论 -
343. Integer Break
题目Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return原创 2017-02-28 22:20:44 · 238 阅读 · 0 评论 -
344. Reverse String
题目Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.Subscribe to see which companies asked this question.思路比较简单,两个index往中间靠,并互换字符原创 2017-02-28 22:24:33 · 201 阅读 · 0 评论 -
345. Reverse Vowels of a String
题目Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, return “leotcede”.Note: The vowe原创 2017-02-28 23:15:41 · 200 阅读 · 0 评论 -
461. Hamming Distance
题目The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note: 0 ≤ x, y < 231.Exa原创 2017-03-01 00:28:12 · 208 阅读 · 0 评论 -
225. Implement Stack using Queues
题目Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return wheth原创 2017-02-21 01:40:05 · 179 阅读 · 0 评论 -
419. Battleships in a Board
题目Given an 2D board, count how many battleships are in it. The battleships are represented with ‘X’s, empty slots are represented with ‘.’s. You may assume the following rules:You receive a valid board原创 2017-03-01 23:51:29 · 254 阅读 · 0 评论 -
412. Fizz Buzz
题目Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For原创 2017-03-02 00:35:33 · 293 阅读 · 0 评论 -
226. Invert Binary Tree
题目Invert a binary tree. 4/ \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howell:原创 2017-02-21 23:43:49 · 152 阅读 · 0 评论 -
228. Summary Ranges
题目Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].Credits: Special thanks to @jianchao.li.fighter for add原创 2017-02-22 00:03:15 · 200 阅读 · 0 评论 -
231. Power of Two
题目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.Subscribe to see which com原创 2017-02-22 23:26:06 · 187 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
题目Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Could y原创 2017-03-03 23:56:25 · 313 阅读 · 0 评论 -
389. Find the Difference
题目Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was added i原创 2017-03-04 00:08:03 · 385 阅读 · 0 评论 -
258. Add Digits
题目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,原创 2017-02-24 23:36:53 · 211 阅读 · 0 评论 -
260. Single Number III
题目Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1原创 2017-02-24 23:51:42 · 211 阅读 · 0 评论 -
283. 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 fun原创 2017-02-26 12:49:04 · 189 阅读 · 0 评论 -
292. Nim Game
题目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 th原创 2017-02-26 13:42:50 · 373 阅读 · 0 评论 -
303. Range Sum Query - Immutable
题目Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example: Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRange(0,原创 2017-02-26 13:53:29 · 191 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one a原创 2017-02-26 20:42:27 · 202 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one a原创 2017-02-26 20:43:00 · 192 阅读 · 0 评论 -
535. Encode and Decode TinyURL
题目Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it原创 2017-03-05 22:06:37 · 1648 阅读 · 0 评论 -
371. Sum of Two Integers
题目Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example: Given a = 1 and b = 2, return 3.Credits: Special thanks to @fujiaozhu for adding this problem原创 2017-03-06 01:11:05 · 498 阅读 · 0 评论 -
504. Base 7
题目Given an integer, return its base 7 string representation.Example 1: Input: 100 Output: “202” Example 2: Input: -7 Output: “-10” Note: The input will be in range of [-1e7, 1e7].Subscribe to see原创 2017-03-06 01:27:42 · 358 阅读 · 0 评论 -
142. Linked List Cycle II
题目Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space?Subscribe to原创 2017-03-20 23:36:13 · 261 阅读 · 0 评论 -
leetcode--344. Reverse String
Write a function that takes a string as input and returns >the string reversed. Example: Given s = “hello”, return “olleh”. char* reverseString(char* s) { char tempChar; int prePoi原创 2016-04-22 22:28:20 · 464 阅读 · 0 评论