10 2017 档案
摘要:1 /** 2 * 两个大数相减,默认没有符号位,且都为正数 3 * 4 * @param a 5 * @param b 6 * @return 7 */ 8 public static String bigDigitalSub(String a, String b) { 9 //翻转字符串并...
阅读全文
摘要:Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Example 2:
阅读全文
摘要:Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th
阅读全文
摘要:Given a complete binary tree, count the number of nodes. 题目含义:给定一个完整二叉树,求所有节点数 百度百科中完全二叉树的定义如下:若设二叉树的深度为h,除第 h 层外,其它各层 (1~h-1) 的结点数都达到最大个数,第 h 层所有的结点都
阅读全文
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic
阅读全文
摘要:Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number m
阅读全文
摘要:Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. Follow up:Wha
阅读全文
摘要: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
阅读全文
摘要: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 ston
阅读全文
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by upd
阅读全文
摘要:Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible
阅读全文
摘要:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smal
阅读全文
摘要:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. Th
阅读全文
摘要:Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed n
阅读全文
摘要:You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from th
阅读全文
摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For exam
阅读全文
摘要:You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subseq
阅读全文
摘要:You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contai
阅读全文
摘要: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
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. 含义:为一个列表排序,要求空间复杂度为常量 思路:使用归并排序 1 public class Solution { 2 public ListNode sor
阅读全文
摘要:Sort a linked list using insertion sort. 含义:用插入排序来对列表进行排序 思路:可以构建一个临时的链表,然后将待排序的链表的每一个节点插入到临时链表中 // 插入排序 public ListNode insertionSortList(ListNode he
阅读全文
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For
阅读全文
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2-
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2
阅读全文
摘要: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 a
阅读全文
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
摘要: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 -
阅读全文
摘要:Reverse a singly linked list. 含义:翻转一个单列表 类似题目:92. Reverse Linked List II
阅读全文
摘要:Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin to in
阅读全文
摘要: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,
阅读全文
摘要: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. 含义:合并另个已
阅读全文
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total
阅读全文
摘要:Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do t
阅读全文
摘要:Given a positive integer n and you can do operations as follow: What is the minimum number of replacements needed for n to become 1? 含义:给定一个正数n,如果n是偶数
阅读全文
摘要:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assum
阅读全文
摘要: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
阅读全文
摘要:Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5,
阅读全文
摘要:Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note:Your algorithm sh
阅读全文
摘要:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: Example 1: Exa
阅读全文
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calcul
阅读全文
摘要:Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: Example 1: Example 2:
阅读全文
摘要: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. 含义:不用加减运算符,计算
阅读全文
摘要: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 fa
阅读全文
摘要: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
阅读全文
摘要:Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), retur
阅读全文
摘要:Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another e
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov
阅读全文
摘要:One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node,
阅读全文
摘要:Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The l
阅读全文
摘要:Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm th
阅读全文
摘要:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1'
阅读全文
摘要:Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The
阅读全文
摘要:Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list -- whose elements may also be integ
阅读全文
摘要: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
阅读全文
摘要: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. to
阅读全文
摘要:Implement a trie with insert, search, and startsWith methods. 题目含义:实现字典树的insert, search, 和startsWith 方法 字典树概念参考http://blog.csdn.net/u012501459/article
阅读全文
摘要:Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of t
阅读全文
摘要:A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents
阅读全文
摘要:Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,
阅读全文
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3-
阅读全文
摘要: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. 题目含义:判断列表是否有环路,如果
阅读全文
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the
阅读全文
摘要:Given a singly linked list, determine if it is a palindrome. 题目含义:给定一个单列表,判断是否构成回文
阅读全文
摘要:Given a linked list, remove the nth node from the end of list and return its head. For example, Note:Given n will always be valid.Try to do this in on
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 题目含义:判断一个列表是否有环路 思路:参考142. Linked List C
阅读全文
摘要:Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string.
阅读全文
摘要:Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 题目含义:不要使用乘 除 取模,计算除法 方法一:
阅读全文
摘要:Implement pow(x, n). 题目含义:实现x的n次方
阅读全文
摘要:Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? 题目含义:给定的数组是有序的,再次找h值 相关题目: 274. H-
阅读全文
摘要:Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If the
阅读全文
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted i
阅读全文
摘要:Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point o
阅读全文
摘要:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is th
阅读全文
摘要: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 c
阅读全文
摘要:We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wron
阅读全文
摘要:There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have t
阅读全文
摘要:Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Input:
阅读全文
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 题目含义:给定一个升序的列表,构造一个平衡二叉树 平衡二叉树:二叉排序树集中了数
阅读全文
摘要:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacen
阅读全文
摘要:Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing su
阅读全文
摘要:Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is b
阅读全文
摘要:There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are:
阅读全文
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating
阅读全文
摘要:Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the u
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to
阅读全文
摘要:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According
阅读全文
摘要:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time
阅读全文
摘要:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled wit
阅读全文
摘要:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Example 2:
阅读全文
摘要:There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. Yo
阅读全文
摘要:Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l]is zero. To make prob
阅读全文
摘要:In English, we have a concept called root, which can be followed by some other words to form another longer word - let's call this word successor. For
阅读全文
摘要:Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2,2,3] and k = 2, return [1,2]. Note: You may assum
阅读全文
摘要:Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be given a list of non-repetitive words to build a di
阅读全文
摘要:Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Example 2: Example 3:
阅读全文
摘要:TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http
阅读全文
摘要:Given an array of integers, every element appears twice except for one. Find that single one. 题目含义:给定的数组中,每个数字出现两次,只有一个数字出现了一次,找出这个数字
阅读全文
摘要:Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to h
阅读全文
摘要:We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1. Now, given an integer arra
阅读全文
摘要:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of th
阅读全文
摘要: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 =
阅读全文
摘要:Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element i
阅读全文
摘要: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 lette
阅读全文
摘要: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
阅读全文
摘要:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This
阅读全文
摘要:Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings consists of lowercase English letters only and the
阅读全文
摘要:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals
阅读全文
摘要:ou are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/ver
阅读全文
摘要:Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Examp
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.
阅读全文
摘要:Given two arrays, write a function to compute their intersection. 题目含义z:计算两个数组的交集,重复的数字要保留
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree [1,null,2,3], return [1,3,2]. 题目含义:用中序遍历树并输出
阅读全文
摘要:Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth
阅读全文
摘要:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: Construct the maximum tree by the given array a
阅读全文
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文
摘要: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
阅读全文
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and
阅读全文
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example:Given the below binary tree and sum
阅读全文
摘要:Given a binary tree, flatten it to a linked list in-place. For example,Given The flattened tree should look like: 方法二:
阅读全文
摘要:Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL
阅读全文
摘要:Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution sti
阅读全文
摘要:You need to find the largest value in each row of a binary tree. Example: 方法二:
阅读全文
摘要:Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [1,2,3]. Note: Recursive solu
阅读全文
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n
阅读全文
摘要:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For exa
阅读全文
摘要:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's
阅读全文
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes
阅读全文
摘要: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 hou
阅读全文
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or
阅读全文
摘要:Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values
阅读全文
摘要:Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Example 2:
阅读全文
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 whic
阅读全文
摘要:Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any oneof them. Two
阅读全文
摘要:Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the roo
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet
阅读全文
摘要:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might
阅读全文
摘要:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. E
阅读全文
摘要:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1:
阅读全文
摘要:Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subt
阅读全文
摘要:Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a
阅读全文
摘要:nvert a binary tree. to 方法二:BfS
阅读全文
摘要:Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node.
阅读全文
摘要:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n
阅读全文
摘要: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 --
阅读全文
摘要:Find the sum of all left leaves in a given binary tree. Example: 方法二:
阅读全文
摘要:Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is define
阅读全文
摘要:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all
阅读全文
摘要:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath betwee
阅读全文
摘要: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
阅读全文
摘要: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. F
阅读全文
摘要: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 l
阅读全文
摘要: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 dept
阅读全文
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题目含义:给定了一个升序的数组,转换成一个平衡二叉树
阅读全文
摘要: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
阅读全文
摘要: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 l
阅读全文
摘要: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 a
阅读全文
摘要:You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t
阅读全文
摘要:The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another n
阅读全文
摘要:Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is positive and will fit within the range of a 32-bi
阅读全文
摘要:Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Example 2:
阅读全文
摘要:We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write
阅读全文
摘要:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n
阅读全文
摘要:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number
阅读全文
摘要:Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: 求两个字符串的加法
阅读全文
摘要:Given a positive integer num, write a function which returns True if num is a perfect square else False. 题目含义:判断一个数能否被开方
阅读全文
摘要:Given an integer, write a function to determine if it is a power of three. 题目含义:给定一个数,判断它是否是3的n次方 思路:使用换底公式
阅读全文
摘要: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:
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two. 题目含义:判断一个数是否是2的n次方
阅读全文
摘要:ount the number of prime numbers less than a non-negative number, n. 题目含义:要求计算小于N的所有素数的个数。素数又称质数,是只能被1和自身整数的数 思路:厄拉多塞筛法 西元前250年,希腊数学家厄拉多塞(Eeatosthese)
阅读全文
摘要: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 intege
阅读全文
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 题目含义:这里我们要求n!末尾有多少个0 思路:
阅读全文
摘要:Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example:
阅读全文
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example:
阅读全文
摘要:Implement int sqrt(int x). Compute and return the square root of x. 题目题目:返回一个int数开方后的结果
阅读全文
摘要:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leadin
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space. 题目含义:不要使用额外空间,判断整数是否为回文
阅读全文
摘要:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 题目含义翻转一个整数 相关题目:190. Reverse Bits
阅读全文
摘要:Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: Given a number n. You have to
阅读全文
摘要:You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. Now, we define a pair (c, d) can follow an
阅读全文
摘要:Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that
阅读全文
摘要:Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:Input: "bbbab
阅读全文
摘要:【基本问题单元的定义】这取决于你所查看问题的角度,找到一个划分,推进问题的角度十分重要。作者找到的方式是dp[ i ][ j ],用来表示 substring( i , j),然后站在这个角度,假设substring(i , j )中的最大的结果是知道的,那么下一步需要确定的是,其如何影响下一个阶段
阅读全文
摘要:You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose o
阅读全文
摘要:Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and t
阅读全文
摘要:In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. For now, suppose you are a domin
阅读全文
摘要:In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach o
阅读全文
摘要:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both
阅读全文
摘要:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the
阅读全文
摘要:Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is po
阅读全文
摘要:Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.
阅读全文
摘要:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example:Given n = 2, return 91. (The answer should be the
阅读全文
摘要: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 pro
阅读全文
摘要:x&(x-1)可以消去最右边的1, 如果判断一个数是否是2的指数的快捷方法,比如8,二进制位1000, 那么8&(8-1)为0,只要为0就是2的指数
阅读全文
摘要: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 r
阅读全文
摘要:Given an unsorted array of integers, find the length of longest increasing subsequence. For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest inc
阅读全文
摘要:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. For example, given n = 12,
阅读全文
摘要: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,
阅读全文