This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "id": 210, | |
| "content": "comment1", | |
| "user_id": 109, | |
| "topic_id": 94, | |
| "created_at": "2015-12-07T00:03:06.750+08:00", | |
| "updated_at": "2015-12-07T00:03:06.750+08:00" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "data": [ | |
| { | |
| "id": 210, | |
| "content": "comment1", | |
| "user_id": 109, | |
| "topic_id": 94, | |
| "created_at": "2015-12-07T00:03:06.750+08:00", | |
| "updated_at": "2015-12-07T00:03:06.750+08:00" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### JavaScript ##### | |
| # Solution1 | |
| var isUgly = function(num) { | |
| if(num <= 0){ | |
| return false; | |
| } else if (num === 1) { | |
| return true; | |
| } | |
| while(num % 2 === 0){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### Ruby ##### | |
| # Solution1 | |
| def climb_stairs(n) | |
| result = [] | |
| result[0] = 0; | |
| result[1] = 1; | |
| result[2] = 2; | |
| for i in 3..n do | |
| result[i] = result[i - 1] + result[i - 2]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### Ruby ##### | |
| # Solution1 | |
| def majority_element(nums) | |
| h = (nums.size.to_f / 2).ceil | |
| sorted = nums.sort | |
| return sorted[h] | |
| end | |
| # Solution2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### Ruby ##### | |
| # Solution1 | |
| def product_except_self(nums) | |
| length = nums.length | |
| result = [1] | |
| for i in 0..(length-2) do | |
| result << result[i] * nums[i] | |
| end | |
| i = length - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### Ruby ##### | |
| # Solution1 | |
| def max_profit(prices) | |
| return 0 if prices.length <= 1 | |
| profit = 0 | |
| for i in 1..(prices.length-1) do | |
| if prices[i] > prices[i-1] | |
| profit = profit + (prices[i] - prices[i-1]) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### JavaScript ##### | |
| # Solution1 | |
| var isAnagram = function(s, t) { | |
| if(s.length !== t.length){ | |
| return false; | |
| } | |
| var checkList = {}; | |
| for(i = 0; i < s.length; i++){ | |
| if(!checkList[s[i]]){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### Ruby ##### | |
| # Solution1 | |
| def contains_duplicate(nums) | |
| result = false | |
| if nums.length == 1 | |
| return result | |
| end | |
| sorted = nums.sort | |
| for i in 0..(sorted.length-2) do |
NewerOlder