[leetcode.com]算法题目 - Pow(x, n)】的更多相关文章

Implement pow(x, n). class Solution { public: double pow(double x, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function ==n) return 1.0; ==n) return x; int k = abs(n); ; ; result = pow(x, k/); result = result*result*…
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order does not matter) 我的答案如下: class So…
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. For example:A = …
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = 6. class Solution { public: int max…
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Fo…
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. /** * Definition for binary tree * struct TreeNode { * int val; *…
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [], [,4], [6,,7], [4,,8,3] ] The minimum path sum from top to bottom is 11 (i.e.,…
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 word is defined as a character sequence consists of non-space cha…
Implement int sqrt(int x). Compute and return the square root of x. class Solution { public: int sqrt(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function ) ; ) ; ; int large=x; ; while(small<large){ int a = x/temp;…
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and bl…