![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 74
happyxuma1991
这个作者很懒,什么都没留下…
展开
-
leetcode——204.——Count Primes
Count the number of prime numbers less than a non-negative number, n.class Solution {public: int countPrimes(int n) { bool *isprime = new bool[n]; for (int i = 0; i < n; i++) {原创 2016-03-29 15:06:06 · 220 阅读 · 0 评论 -
leetcode——203——Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5class Solution {public:原创 2016-03-29 15:31:00 · 184 阅读 · 0 评论 -
leetcode——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 o原创 2016-03-29 16:41:25 · 229 阅读 · 0 评论 -
leetcode——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 house原创 2016-03-29 17:15:54 · 184 阅读 · 0 评论 -
leetcode——191——Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has binary representation 000000000原创 2016-03-29 17:26:58 · 199 阅读 · 0 评论 -
leetcode——190——Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101原创 2016-03-29 17:47:11 · 199 阅读 · 0 评论 -
leetcode——189——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]. Note:Try to come up as many solutions as you ca原创 2016-03-29 19:46:11 · 219 阅读 · 0 评论 -
leetcode——172——Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.class Solution {public: int trailingZeroes(int n) { int原创 2016-03-29 20:29:31 · 184 阅读 · 0 评论 -
leetcode—— 171——Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.class Solution {public: int titleToNumber(string s) { int ret = 0; for(int i = 0; i < s.原创 2016-03-29 20:41:33 · 165 阅读 · 0 评论 -
leetcode——169——Majority Element
Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alw原创 2016-03-29 21:08:33 · 188 阅读 · 0 评论 -
leetcode——168——Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB class Sol原创 2016-03-29 21:32:09 · 189 阅读 · 0 评论 -
leetcode——165—— Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2016-03-31 22:31:06 · 171 阅读 · 0 评论 -
leetcode——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 ↘原创 2016-04-01 11:53:15 · 157 阅读 · 0 评论 -
leetcode——155—— 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() -- Ge原创 2016-04-02 10:51:28 · 210 阅读 · 0 评论 -
leetcode——125——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a pa原创 2016-04-02 11:26:28 · 207 阅读 · 0 评论 -
leetcode——118—— 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]]Subscribe to see w原创 2016-04-02 12:28:26 · 204 阅读 · 0 评论 -
leetcode——119——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]. Note:Could you optimize your algorithm to use only O(k) extra space?Subscribe t原创 2016-04-02 15:27:31 · 197 阅读 · 0 评论 -
leetcode——112——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 and sum =原创 2016-04-03 11:53:43 · 192 阅读 · 0 评论 -
leetcode——111——Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary t原创 2016-04-03 12:51:37 · 161 阅读 · 0 评论 -
leetcode——110——Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never diffe原创 2016-04-03 13:56:20 · 180 阅读 · 0 评论 -
leetcode——102——Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /原创 2016-04-03 15:02:20 · 175 阅读 · 0 评论 -
leetcode——104—— Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Subscribe to see which companies ask原创 2016-04-03 15:05:19 · 192 阅读 · 0 评论 -
leetcode——107——Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2016-04-03 16:12:11 · 210 阅读 · 0 评论 -
leetcode——101——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 3But the fo原创 2016-04-03 18:34:50 · 190 阅读 · 0 评论 -
leetcode——100—— 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./** * D原创 2016-04-03 18:57:18 · 177 阅读 · 0 评论 -
leetcode——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原创 2016-03-22 17:58:45 · 227 阅读 · 0 评论 -
leetcode——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 the原创 2016-03-22 18:28:52 · 230 阅读 · 0 评论 -
leetcode——290——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 in原创 2016-03-22 21:31:54 · 254 阅读 · 0 评论 -
leetcode——278—— 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 based on the原创 2016-03-22 22:40:59 · 204 阅读 · 0 评论 -
leetcode——263——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 not ugly sin原创 2016-03-22 22:49:16 · 161 阅读 · 0 评论 -
leetcode——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 on原创 2016-03-22 22:56:44 · 225 阅读 · 0 评论 -
leetcode——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原创 2016-03-22 19:55:12 · 234 阅读 · 0 评论 -
leetcode——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 func原创 2016-03-22 19:05:13 · 265 阅读 · 0 评论 -
leetcode——88——Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal tom + n) to hold addit原创 2016-04-05 22:07:08 · 196 阅读 · 0 评论 -
leetcode——83——Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. /** * Definition for原创 2016-04-05 22:31:06 · 185 阅读 · 0 评论 -
leetcode——1——Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums = [2,原创 2016-04-05 23:13:47 · 211 阅读 · 0 评论 -
leetcode——257——Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]class Sol原创 2016-03-23 21:20:39 · 183 阅读 · 0 评论 -
leetcode——237——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 with value原创 2016-03-23 21:46:51 · 163 阅读 · 0 评论 -
leetcode——235——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 defined betw原创 2016-03-23 22:05:31 · 171 阅读 · 0 评论 -
leetcode——6——ZigZag Conversion
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 P L S I I原创 2016-04-06 12:46:46 · 198 阅读 · 0 评论