Question:Implement int sqrt(int x).Compute and return the square root of x.Anwser 1: 二分法class Solution {public: int sqrt(int x) { if(x < 0) return -1; // assert(x >= 0); long long x2 = (long long)x;
Question:Given a number represented as an array of digits, plus one to the number.Anwser 1: szie -> 0class Solution {public: vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below /
Question:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given
Question:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Anwser 1: class Solution {public: string addBinary(string a, string b) { // Start typing your C/C++ solution below
極限編程的核心有四個:交流、簡單、反饋、勇氣這四個原則大家在平時做項目的過程中一定也注意到了,但是兩位大師 Kent Beck 和 Martin Fowler 能夠把這四點歸結在一起,使他們能夠共同組成極限編程這架四輪馬車,卻是一個不小的創造的。下面僅就自己的學習和簡單的實踐過程中遇到的問題來談談自己對這四個核心的一些理解。一、 交流 1) 開發人員與客戶的交流
Question: Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Anwser 1: O(n^3) based-on Rowclass Solution {public: bool check(int row, int* colArray) { for (int i = 0;
Question: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 = 22, 5 / \
Question: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 = 22, 5 / \ 4 8 / / \ 11 13 4
Question: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 which represents the number 123.Find the total sum of all root-to-leaf numbers.For
線程類public class MyRunnable implements Runnable{ int i =0; public void run(){ for(;i<30;i++){ System.out.println("x========"+Thread.currentThread().getName());