PIXNET Logo登入

CONY的世界

跳到主文

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

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

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 3月 22 週四 201804:20
  • Leetcode Tree,Linkedlist 114 @ Java

114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
(繼續閱讀...)
文章標籤

angledark0123 發表在 痞客邦 留言(1) 人氣(369)

  • 個人分類:Algorithm medium
▲top
  • 3月 06 週二 201802:24
  • Leetcode DP 764 @ Java

764. Largest Plus Sign
In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except those cells in the given list mines which are 0. What is the largest axis-aligned plus sign of 1s contained in the grid? Return the order of the plus sign. If there is none, return 0.
(繼續閱讀...)
文章標籤

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

  • 個人分類:Algorithm medium
▲top
  • 2月 19 週一 201801:26
  • Leetcode contest-2/17- BFS 785 @ Java

785. Is Graph Bipartite?
Given a graph, return true if and only if it is bipartite.
(繼續閱讀...)
文章標籤

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

  • 個人分類:Algorithm medium
▲top
  • 2月 10 週六 201803:38
  • Leetcode Math 670 @Java

670. Maximum Swap

Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.


Example 1:


Input: 2736
Output: 7236
Explanation: Swap the number 2 and the number 7.

 


Example 2:


Input: 9973
Output: 9973
Explanation: No swap.

 


Note:



  1. The given number is in the range [0, 108]


 


這邊的思維是loop from MSB到LSB,然後每位要用往後找是否有比自己更大的


(不能用往前看,找比自己小的最大位,因為無法確定目前的數字換完就是最大的


ex. 98368 --> 98863,如果用往前找小的,會變成98638,但是其實最佳的換法是8跟3 換)


所以要用小的數往後找最大值來看(因為9一定會讓值是最大,不管在哪位)


一但找到就可以swap 後return 


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

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

  • 個人分類:Algorithm medium
▲top
  • 2月 09 週五 201801:37
  • Leetcode BFS 127 @ Java

127. Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
(繼續閱讀...)
文章標籤

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

  • 個人分類:Algorithm medium
▲top
  • 2月 06 週二 201803:55
  • Leetcode UnionFind 261 @Java

261. Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.
(繼續閱讀...)
文章標籤

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

  • 個人分類:Algorithm medium
▲top
  • 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 週二 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) 人氣(22)

  • 個人分類: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月 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
12...4»

個人資訊

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

Top Posts

  • (16,621)什麼是Library(函式庫,大陸稱庫)
  • (1,600)" 食物GI值 " 的大整理
  • (851)我不知道風是在哪一個方向吹 徐志摩
  • (392)「大考大玩,小考小玩」的真實意義
  • (330)台北Mei’s Tea Bar ~好吃又特別的蘋果鬆餅
  • (276)fedora快捷鍵
  • (159)寫程式語言人的痛(同感)
  • (48)終章---費玉清 唱
  • (36)很妙的人
  • (9)兩天一夜台北遊 part1 -元定食

文章分類

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] 射手白馬 於文章「心情雜記...」發表了一則私密留言

文章精選

文章搜尋

誰來我家

參觀人氣

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