查看完整版本 : LeetCode

Susan﹏汪汪 2016-7-19 07:28 AM

[quote]原帖由 [i]darigold[/i] 於 2016-7-18 11:13 PM 發表 [url=http://www.discuss.com.hk/redirect.php?goto=findpost&pid=444871752&ptid=24497948][img]http://www.discuss.com.hk/images/common/back.gif[/img][/url]


那應該是 BitwiseAnd(self, self -1) ?

&- 這個operator好奇怪 …… [/quote]
+ - * operator有overflow checking
&+ &- &*會忽略overflow

因為前面已經check左self > 0
所以可以用&- operator
會比- operator快少少



[url=http://www.discuss.com.hk/iphone][img=100,23]http://i.discuss.com.hk/d/images/r10/iphoneD.jpg[/img][/url]

darigold 2016-7-28 12:30 PM

雖然怪,但係opt-out overflow checking per operator 這個設計我喜歡。

再來一題︰[url=http://andrew-algorithm.blogspot.com/2016/05/leetcode-oj-reverse-string.html]LeetCode OJ - Reverse String[/url]

Susan﹏汪汪 2016-7-28 04:20 PM

[code]class Solution {
    func reverseString(s: String) -> String {
        return String(s.characters.reverse())
    }
}[/code]

Susan﹏汪汪 2016-7-28 04:36 PM

C++ version[code]class Solution {
public:
    string reverseString(string s) {
        auto begin = s.begin();
        auto rbegin = s.rbegin();
        const auto end = s.end();
        const auto rend = s.rend();
        for (;begin < rbegin.base();begin++, rbegin++) {
            swap(*begin, *rbegin);
        }
        return s;
    }
};[/code]感覺上有bug
本來應該要check清楚所有條件先...不過咁嘅答案都照accepted...

[[i] 本帖最後由 Susan﹏汪汪 於 2016-7-28 04:40 PM 編輯 [/i]]

darigold 2016-8-1 08:17 AM

[url=http://andrew-algorithm.blogspot.com/2016/05/leetcode-oj-reverse-vowels-of-string.html]LeetCode OJ - Reverse Vowels of a String[/url]

darigold 2016-8-7 10:47 PM

[url=http://andrew-algorithm.blogspot.com/2016/05/leetcode-oj-intersection-of-two-arrays.html]LeetCode OJ - Intersection of Two Arrays[/url]

Susan﹏汪汪 2016-8-8 01:16 PM

[code]return Array(Set(nums1).intersect(nums2))[/code]

darigold 2016-8-10 11:52 AM

[url=http://andrew-algorithm.blogspot.com/2016/06/leetcode-oj-data-stream-as-disjoint.html]LeetCode OJ - Data Stream as Disjoint Intervals[/url]

darigold 2016-8-21 05:28 AM

[url=http://andrew-algorithm.blogspot.com/2016/06/leetcode-oj-valid-perfect-square.html]LeetCode OJ - Valid Perfect Square[/url]

darigold 2016-8-24 09:58 AM

[url=http://andrew-algorithm.blogspot.com/2016/06/leetcode-oj-water-and-jug-problem.html]LeetCode OJ - Water and Jug Problem[/url]

darigold 2016-8-29 01:09 AM

[url=http://andrew-algorithm.blogspot.com/2016/07/leetcode-oj-lru-cache.html]LeetCode OJ - LRU Cache[/url]

darigold 2016-9-1 12:01 PM

[url=http://andrew-algorithm.blogspot.com/2016/07/leetcode-oj-design-twitter.html]LeetCode OJ - Design Twitter[/url]

哈伯馬斯 2016-9-7 11:52 AM

Leetcode難唔難學?

darigold 2016-9-7 02:36 PM

[quote]原帖由 [i]哈伯馬斯[/i] 於 2016-9-7 11:52 AM 發表 [url=http://computer.discuss.com.hk/redirect.php?goto=findpost&pid=447639854&ptid=24497948][img]http://computer.discuss.com.hk/images/common/back.gif[/img][/url]
Leetcode難唔難學?
[/quote]

Leetcode 係一個網站,佢唔係一種編程技術,所以你冇得「學 Leetcode」

根據我的了解,因為好多國外既大公司都用算法題來面試,所以好多人開始操題,就有人開左LeetCode呢個網站俾人線習面試算法題。

所以如果說學習Leetcode,不如說學習算法。

你有冇編程經驗?有既話可以從easy做起試試。例如這題 [url]https://leetcode.com/problems/bulls-and-cows/[/url]

darigold 2016-9-14 07:08 AM

[url=http://andrew-algorithm.blogspot.com/2016/07/leetcode-oj-russian-doll-envelopes.html]LeetCode OJ - Russian Doll Envelopes[/url]

darigold 2016-9-18 10:42 PM

[url=http://andrew-algorithm.blogspot.com/2016/07/leetcode-oj-largest-divisible-subset.html]LeetCode OJ - Largest Divisible Subset[/url]

darigold 2016-9-23 10:35 PM

[url=http://andrew-algorithm.blogspot.com/2016/07/leetcode-oj-wiggle-subsequence.html]LeetCode OJ - Wiggle Subsequence[/url]

darigold 2016-9-27 11:01 PM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-guess-number-higher-or-lower.html]LeetCode OJ - Guess Number Higher or Lower[/url]

Susan﹏汪汪 2016-9-27 11:19 PM

[quote]原帖由 [i]darigold[/i] 於 2016-9-27 11:01 PM 發表 [url=http://www.discuss.com.hk/redirect.php?goto=findpost&pid=448773557&ptid=24497948][img]http://www.discuss.com.hk/images/common/back.gif[/img][/url]
LeetCode OJ - Guess Number Higher or Lower [/quote]
以前初中用計數機寫過個game

darigold 2016-9-30 10:02 PM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-longest-absolute-file-path.html]LeetCode OJ - Longest Absolute File Path[/url]

ken2016man 2016-9-30 11:57 PM

我solve左好多question...都幾easy下 ....:lDD_003:

darigold 2016-10-2 06:29 AM

[quote]原帖由 [i]ken2016man[/i] 於 2016-9-30 11:57 PM 發表 [url=http://computer.discuss.com.hk/redirect.php?goto=findpost&pid=448944523&ptid=24497948][img]http://computer.discuss.com.hk/images/common/back.gif[/img][/url]
我solve左好多question...都幾easy下 ....:lDD_003:
[/quote]
很好,加油!
:smile_o12:

darigold 2016-10-9 11:24 AM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-first-unique-character-in.html]LeetCode OJ - First Unique Character in a String[/url]

darigold 2016-10-14 11:56 PM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-lexicographical-numbers.html]LeetCode OJ - Lexicographical Numbers[/url]

darigold 2016-10-18 11:07 PM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-find-difference.html]LeetCode OJ - Find the Difference[/url]

AC-Fans 2016-10-21 12:08 PM

submit左都唔可以睇人地D答案?

darigold 2016-10-21 01:44 PM

[quote]原帖由 [i]AC-Fans[/i] 於 2016-10-21 12:08 PM 發表 [url=http://computer.discuss.com.hk/redirect.php?goto=findpost&pid=450141184&ptid=24497948][img]http://computer.discuss.com.hk/images/common/back.gif[/img][/url]
submit左都唔可以睇人地D答案?
[/quote]
其實唔 submit 都可以睇 discussion forum。
GitHub 一 search 一大堆。
小弟個 blog 也有不少。

darigold 2016-10-26 01:26 PM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-elimination-game.html]LeetCode OJ - Elimination Game[/url]

darigold 2016-10-30 12:05 AM

這題有點可惜了,難得想到一個 O(n) 的算法,可惜 unordered_map 用了太多的 memory

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-perfect-rectangle-i.html]LeetCode OJ - Perfect Rectangle (I)[/url]

darigold 2016-11-4 10:45 PM

[url=http://andrew-algorithm.blogspot.com/2016/09/leetcode-oj-mini-parser.html]LeetCode OJ - Mini Parser[/url]
頁: 1 2 3 4 5 6 7 8 9 [10] 11 12 13 14 15 16 17 18
查看完整版本: LeetCode