Question : Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Anwser 1 : class Solution {public: string intToRoman(int num) { // Start typing your C/C++ solution below // DO
Question :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 alternate between).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /
定義 裝飾者模式:動態將責任附加到對象上,若要擴充功能,裝飾者提供比繼承更有彈性的替代方案。就增加功能來說,Decorator模式相比產生子類更為靈活。設計原則: 相信大家現在對裝飾者模式都應該很清楚了吧!那麼,就像我們在前面的文章裡反覆強調的一樣,設計原則遠比模式重要,學習設計模式的同時一定要注意體會設計原則的應用。這裡我們再來看看裝飾者模式裡都符合那些主要的設計原則。1、 Identify the aspects of your application
Question : Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor
Question : Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous. You should gather all requirements up
Quesion : Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple
Question : Divide two integers without using multiplication, division and mod operator.Anwser 1 : class Solution {public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below // DO NOT write int
Question : Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not engage in multiple transactions at the same
Question :Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Anwser 1 : class Solution {public: int toNum(char c) { switch(c) { case 'I':
Question :Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor