PIXNET Logo登入

CONY的世界

跳到主文

在這裡我不是要向大家講述我的生活,只是想留著一些回憶

部落格全站分類:生活綜合

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 2月 01 週四 201812:44
  • Leetcode DP 337 @ Java

337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(14)

  • 個人分類:Algorithm medium
▲top
  • 1月 30 週二 201809:52
  • Leetcode Heap 23 @ Java

23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(15)

  • 個人分類:hard
▲top
  • 1月 30 週二 201800:51
  • Leetcode BinaryTree 116, 117 @ Java

116. Populating Next Right Pointers in Each Node

Given a binary tree


 struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}

 


Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.


Initially, all next pointers are set to NULL.


Note:



  • You may only use constant extra space.

  • You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).


 


For example,

Given the following perfect binary tree,


 1
/ \
2 3
/ \ / \
4 5 6 7

 


After calling your function, the tree should look like:


 1 -> NULL
/ \
2 -> 3 -> NULL
/ \ / \
4->5->6->7 -> NULL

 

注意這題的需求


1. use only extra constant space       ----> cann't use resursive. use iterative to do the recursive work


2.perfect binary tree --> each nonleaf node has two child


這題基本上就是一個node做好兩件事情,


1. 把自己的 left child next 跟 right child 接好


2.如果自己有next,就把right child next 也跟 自己的next.left接好


然後一層一層做就可以了


(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(23)

  • 個人分類:Algorithm medium
▲top
  • 1月 25 週四 201813:07
  • Leetcode Stack 341,636 @ Java

341. Flatten Nested List Iterator

Given a nested list of integers, implement an iterator to flatten it.


Each element is either an integer, or a list -- whose elements may also be integers or other lists.


Example 1:

Given the list [[1,1],2,[1,1]],


By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].


 


Example 2:

Given the list [1,[4,[6]]],


By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6].


 

這一題要注意的地方是 NestedInteger 要在 hasNext() 裡面展開,而不是在next()


因為如果展開後沒有integer 要return false


ex.[ [ ] ] 的測資


如果是在next 裡面展開就會錯誤,因為實際上根本沒有可以return的 integer


(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(8)

  • 個人分類:Algorithm medium
▲top
  • 1月 25 週四 201811:16
  • Leetcode String 44 @ Java


 










444. Wildcard Matching



(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(4)

  • 個人分類:hard
▲top
  • 1月 24 週三 201802:22
  • Leetcode Array 621 @ Java

621. Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(15)

  • 個人分類:Algorithm medium
▲top
  • 1月 10 週三 201808:48
  • Leetcode 56 @ Java

56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(28)

  • 個人分類:Algorithm medium
▲top
  • 1月 08 週一 201808:35
  • Leetcode 761 @ Java

761. Special Binary String
Special binary strings are binary strings with the following two properties:
 
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(31)

  • 個人分類:hard
▲top
  • 1月 07 週日 201808:13
  • Leetcode 139, 238 @ Java

139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may assume the dictionary does not contain duplicate words.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(11)

  • 個人分類:Algorithm medium
▲top
  • 1月 05 週五 201809:59
  • Leetcode 236, 43 @ Java

236. Lowest Common Ancestor of a Binary Tree 

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).”
_______3______
/ \
___5__ ___1__
/ \ / \
6 _2 0 8
/ \
7 4

For example, the lowest common ancestor (LCA) of nodes 5 and 1 is 3. Another example is LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.
這題其實當初我想得太複雜了.....(注意!其實很多題目都是這樣,看清楚題目給的條件,有時候題目加上限制後會變得非常簡單)
如果今天是要找不知道存不存在的兩個node 那這個解法一定不行,但是這題因為是確定存在樹上的兩點node,所以就變得非常簡單
只要思考這兩個node會在樹上存在的可能組合就能找出這組的答案了
一種就是分別在左右subtree,一種就是都在同一個subtree,
左右的情形就是都存在時,那個node就是root了,而當在同一個subtree時,就是第一個相等的那個node開始return就好
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(0) 人氣(7)

  • 個人分類:Algorithm medium
▲top
«123...61»

個人資訊

angledark0123
暱稱:
angledark0123
分類:
生活綜合
好友:
累積中
地區:

Top Posts

  • (1,600)" 食物GI值 " 的大整理
  • (863)我不知道風是在哪一個方向吹 徐志摩
  • (397)「大考大玩,小考小玩」的真實意義
  • (330)台北Mei’s Tea Bar ~好吃又特別的蘋果鬆餅
  • (162)寫程式語言人的痛(同感)
  • (133)何其芳〈夢中道路〉
  • (48)終章---費玉清 唱
  • (9)兩天一夜台北遊 part1 -元定食
  • (3)告訴你我在忙什麼
  • (1)多事之際

文章分類

toggle leetcode (3)
  • Algorithm medium (32)
  • easy (5)
  • hard (6)
  • google (1)
  • 拜家 (4)
  • 學習 (102)
  • 生活隨筆 (49)
  • 旅遊 (16)
  • 美食 (9)
  • 未分類文章 (1)

最新文章

  • Leetcode Tree,Linkedlist 114 @ Java
  • Leetcode DP 764 @ Java
  • Leetcode Greedy 316 @ Java
  • Leetcode DP 140 @Java
  • Google CodeJam I/O for women 2/17- Graph-Centrist
  • Leetcode contest-2/17- BFS 785 @ Java
  • Leetcode Math 670 @Java
  • Leetcode Graph 269 @Java
  • Leetcode BFS 127 @ Java
  • Leetcode UnionFind 261 @Java

最新留言

  • [24/08/12] 訪客 於文章「減重整理...」留言:
    瘦身要有效最重要的是提升自身代謝力 唯有代謝提高後,又...
  • [23/09/23] 新飛Hsinfei 於文章「最近英文課一波三折...」留言:
    都是為了連假!辛苦的補班英文該怎麼說?連假英文呢? http...
  • [22/04/27] 訪客 於文章「Create customized MP...」留言:
    原本在搜尋引擎找出一堆 Blog 文章,不知哪幾篇值得花時間...
  • [20/12/17] 哈 於文章「Leetcode Tree,Linked...」留言:
    爛...
  • [17/09/18] 老菜 於文章「Win7上灌vc6...」留言:
    您好,請問您還有FileTool這個補丁嗎?MicroSof...
  • [17/08/19] Tim Feng 於文章「Leetcode Stack 71,40...」留言:
    你好,我最近在學python,分析各位先賢們的專案。從200...
  • [16/11/09] Blake Hung 於文章「C/C++之指標 (pointer),參...」留言:
    非常詳盡,謝謝!...
  • [16/06/18] 路人 於文章「什麼是Library(函式庫,大陸稱庫)...」留言:
    黃色字很不清楚,不容易看。...
  • [15/04/20] 訪客 於文章「vim附件:cscope+ctag 使用...」留言:
    Ctrl+/ 再按s 表示:cs find s命令 ==>C...
  • [14/03/20] 射手白馬 於文章「心情雜記...」發表了一則私密留言

文章精選

文章搜尋

誰來我家

參觀人氣

  • 本日人氣:
  • 累積人氣: