114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
angledark0123 發表在 痞客邦 留言(1) 人氣(367)
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) 人氣(27)
316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.
angledark0123 發表在 痞客邦 留言(0) 人氣(20)
140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dictionary does not contain duplicate words.
angledark0123 發表在 痞客邦 留言(0) 人氣(8)
題目落落長 https://codejam.withgoogle.com/codejam/contest/dashboard?c=8384486#s=p2
簡化來說就是要判斷如果是任意 字母排序,判斷某word 是否可以在中間
angledark0123 發表在 痞客邦 留言(0) 人氣(29)
785. Is Graph Bipartite?
Given a graph, return true if and only if it is bipartite.
angledark0123 發表在 痞客邦 留言(0) 人氣(83)
670. Maximum SwapGiven 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:
- 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)
angledark0123 發表在 痞客邦 留言(0) 人氣(38)
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)
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)