![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode刷题
文章平均质量分 65
IT独白者
这个作者很懒,什么都没留下…
展开
-
LeetCode Ugly Number
题目描述: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原创 2015-08-25 00:10:45 · 430 阅读 · 0 评论 -
LeetCode Ugly Number II
题目:Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the f原创 2015-08-25 16:45:24 · 414 阅读 · 0 评论 -
LeetCode Zigzag Convert
题目:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA原创 2015-08-26 17:40:16 · 328 阅读 · 0 评论 -
LeetCode Excel Sheet Column Title
题目:Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3原创 2015-08-27 13:08:57 · 366 阅读 · 0 评论 -
LeetCode Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example ,given the following binary tree: 12 3 这样的一棵树,那么它的从根到叶子节点的路径就是["1 -> 2 -> 5","1 -> 3"]。 5原创 2015-08-30 20:31:02 · 326 阅读 · 0 评论 -
Length of Last Word
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A原创 2015-08-31 15:48:15 · 366 阅读 · 0 评论 -
Factorial Trailing Zeroes
题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.中文:计算n!的末位全是0的个数。注意:此题按照常规方法计算,会出现超时的现象。首先思考:因为要计算末位为0的个数原创 2015-09-01 19:11:35 · 304 阅读 · 0 评论 -
LeetCode Valid Anagram
题目: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.中文翻译:就是要找原创 2015-09-02 15:45:04 · 368 阅读 · 0 评论 -
LeetCode Delete Node in a Linked List
题目:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node原创 2015-09-03 16:51:32 · 321 阅读 · 0 评论 -
LeetCode First Bad Version
题目:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed bas原创 2015-09-09 09:11:16 · 371 阅读 · 0 评论 -
LeetCode Roman to Integer
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.中问题意:就是给一个罗马数字,将其转化为我们平常用的阿拉伯数字。首先我百度了下什么是罗马数字:罗马数字是阿拉伯数字传入之前使用的一种数码。罗马数字采用原创 2015-09-05 12:05:47 · 332 阅读 · 0 评论 -
LeetCode MergeTwoLists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.题意:将两个已经排好序的链表进行合并。题解:此题已经有变种了,而且不用考虑合并之后的原创 2015-09-25 12:19:41 · 2082 阅读 · 0 评论 -
LeetCode Implement Queue using Stacks
题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front eleme原创 2015-09-11 09:36:27 · 335 阅读 · 0 评论 -
LeetCode Rotate Array
题目:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].题意:这题其实是关于数组中的数字反转的题,这里的k有可能会大于这个7,其原创 2015-09-11 22:06:38 · 301 阅读 · 0 评论 -
LeetCode Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321就是用来反转一个整数。但是这题有一些特例要当心:Have you thought about this?Here are some good questions to ask原创 2015-09-06 21:46:51 · 318 阅读 · 0 评论 -
LeetCode Lowest Common Ancestor of a Binary Search Tree
题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defin原创 2015-09-07 17:27:58 · 383 阅读 · 0 评论 -
LeetCode Palindrome Linked List
题目:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?就是考虑一个单链表中的数据是否是回文数。并且要求能否在时间复杂度为O(n)何空间复杂度为O(1)的范围内完成。这道题目不难,我考虑用两原创 2015-09-08 09:49:32 · 269 阅读 · 0 评论 -
LeetCode Maximum Depth of Binary Tree
题目:就是来计算一棵二叉树的最大深度。首先我们设想,二叉树的最大深度,就是由最底层的深度所决定,但是具体是左子树还是右子树的深度,这个就得根据具体这棵树的结构决定了,那么我们如何来计算呢?首先我想到的是用递归来计算,就是从左子树和右子树来看,通过递归去遍历。class TreeNode{ int val; TreeNode left; Tree原创 2015-09-13 15:14:50 · 398 阅读 · 0 评论 -
LeetCode Number of 1 Bits
题目: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 representati原创 2015-09-29 09:22:40 · 300 阅读 · 0 评论 -
LeetCode Power of Two
题目:Given an integer, write a function to determine if it is a power of two.题意:判断一个数是否是2的幂。这道题常规方法肯定不能用,因为如果用常规方法,碰到数很大,那么就会出现超时等情况。后来LZ在网上看到一个方法,还是利用位运算,设想将那个十进制数转换为二进制,然后利用按位与&运算和n - 1,如果得到的结原创 2015-09-29 09:56:23 · 359 阅读 · 0 评论 -
LeetCode Count and Say
题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is rea原创 2015-10-17 09:28:23 · 378 阅读 · 0 评论 -
LeetCode Pascal's Triangle II
题目:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].题意:就是给定一个K值,然后计算出第K行的杨辉三角。注意的是,这里的虽说是第K列,但是其实计数的时候是从0开始计数,这与前一篇博客中的那一题不同,那题是从原创 2015-10-01 16:22:31 · 368 阅读 · 0 评论 -
LeetCode Plus One
题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.题意:就是将一个非负数原创 2015-09-30 19:06:15 · 399 阅读 · 0 评论 -
LeetCode Climb Stairs
题目: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?题意:就是上楼梯的方式的种数。每次只能原创 2015-09-30 19:50:02 · 519 阅读 · 0 评论 -
LeetCode Count Primes
题目:Count the number of prime numbers less than a non-negative number, n题意:统计比n小的整数下的质数个数。解题思路:首先一拿到这题,LZ的思路就是很简单的采用遍历,然后依次去判断每个数是否能被2整除,如果这个数能被某个数整除,那么就说明它不是质数,而且这里对于每个数不用循环到n位置,只要到sqrt即可。原创 2015-10-19 14:37:15 · 312 阅读 · 0 评论 -
LeetCode Bulls and Cows
题目:You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it. Each time your friend guesses a number, you give a hin原创 2015-11-04 00:13:08 · 374 阅读 · 0 评论 -
LeetCode Pascal's Triangle
题目:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]题意:输入一个n,然后得到相应的帕斯卡原创 2015-10-01 15:25:14 · 263 阅读 · 0 评论 -
Min Stack
题目:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top(原创 2015-10-19 22:52:05 · 328 阅读 · 0 评论 -
Word Pattern
题目:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word原创 2015-10-20 22:00:48 · 330 阅读 · 0 评论 -
LeetCode Integer to Roman
题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.题意:就是给定一个整数,将其转化为一个罗马数字。其中确保这个整数是在1到3999的范围内。因为看罗马数字的定义,发现其实如果罗马数字比较大,那么就原创 2015-11-05 11:07:37 · 275 阅读 · 0 评论 -
LeetCode Single Number
题目:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without原创 2015-11-04 23:39:15 · 271 阅读 · 0 评论 -
LeetCode Contains Duplicate
题目: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 ele原创 2015-09-16 09:26:20 · 409 阅读 · 0 评论 -
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() -- Re原创 2015-10-20 18:31:31 · 305 阅读 · 0 评论 -
Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.题意:就是在一个已经排好序的原创 2015-09-17 09:09:13 · 357 阅读 · 0 评论 -
LeetCode Same Tree
题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.题意:原创 2015-10-07 11:13:51 · 302 阅读 · 0 评论 -
LeetCode Invert Binary Tree
题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1题意:将一棵二叉树反转,因为有两种方法,我考虑用非递归的方法来实现。也就是考虑用一个队列LinkedList,然后先将节点依原创 2015-10-07 15:40:48 · 344 阅读 · 0 评论 -
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 ↘ ...原创 2015-10-21 15:16:18 · 301 阅读 · 0 评论 -
LeetCode Path Sum
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree原创 2015-10-07 12:54:50 · 335 阅读 · 0 评论 -
LeetCode Symmetric Tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2015-10-08 17:02:46 · 274 阅读 · 0 评论 -
LeetCode 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 majori原创 2015-10-08 15:27:38 · 325 阅读 · 0 评论