上一页 1 ··· 6 7 8 9 10 11 12 13 14 15 下一页

2018年8月28日

179. Largest Number

摘要: Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Example 2: 阅读全文

posted @ 2018-08-28 20:13 猪猪🐷 阅读(102) 评论(0) 推荐(0)

最左侧的1

摘要: 类似如下grid:每个横⾏行行只要出现1,右边的数字都会是1。例例⼦子中的最左侧的1是倒数第⼆二⾏行行第⼆二列列的那 个。
000011
001111 000001 001111 011111 000111 public int[] leftMostOne(int[][] grid){ // col firCol = getLeft(grid[0]); ... 阅读全文

posted @ 2018-08-28 20:12 猪猪🐷 阅读(133) 评论(0) 推荐(0)

找到所有的subsets的min和max的和⼩小于等于 target

摘要: 在⼀一个⽆无序的数列列⾥里里⾯面,找到所有的subsets的min和max的和⼩小于等于 target,返回subsets的个数。可以优化到O(n). // get all the subsets of the the number // get min , max of each susbet // get the sum of min and max , compare with ... 阅读全文

posted @ 2018-08-28 20:11 猪猪🐷 阅读(243) 评论(0) 推荐(0)

whether a subarray sums up to the target

摘要: Input:
A seq of int A target int 5
Output:
whether a continuous subseq sums up to the target
target 5 -> True. more info on 1point3acres
target 4 -> True
target 6 -> False
follow up: 分析时间复杂度,空间复杂度,改... 阅读全文

posted @ 2018-08-28 20:10 猪猪🐷 阅读(135) 评论(0) 推荐(0)

684. Redundant Connection

摘要: In this problem, a tree is an undirected graph that is connected and has no cycles. The given input is a graph that started as a tree with N nodes (wi 阅读全文

posted @ 2018-08-28 20:08 猪猪🐷 阅读(173) 评论(0) 推荐(0)

Tweaked Identical Binary Tree

摘要: 1 1 / \ / \ 2 3 and 3 2 / \ 4 4 是扭转后可等价的二叉树。 1 1 / \ / \ 2 3 and 3 2 / / 4 4 作者:Jason_Yuan链接:https://www.jianshu.com/p/0623cf8ad71b來源:简书简书著作权归作者所有,任何形 阅读全文

posted @ 2018-08-28 20:08 猪猪🐷 阅读(87) 评论(0) 推荐(0)

647. Palindromic Substrings

摘要: Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are c 阅读全文

posted @ 2018-08-28 20:08 猪猪🐷 阅读(73) 评论(0) 推荐(0)

93. Restore IP Addresses

摘要: public String substring(int startIndex): This method returns new String object containing the substring of the given string from specified startIndex 阅读全文

posted @ 2018-08-28 20:07 猪猪🐷 阅读(102) 评论(0) 推荐(0)

155. Min Stack

摘要: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov 阅读全文

posted @ 2018-08-28 20:06 猪猪🐷 阅读(78) 评论(0) 推荐(0)

617. Merge Two Binary Trees

摘要: Approach #2 Iterative Method [Accepted] Algorithm In the current approach, we again traverse the two trees, but this time we make use of a stackstack  阅读全文

posted @ 2018-08-28 20:06 猪猪🐷 阅读(116) 评论(0) 推荐(0)

Random Pick Index

摘要: Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number m 阅读全文

posted @ 2018-08-28 20:05 猪猪🐷 阅读(145) 评论(0) 推荐(0)

2018年8月17日

238. Product of Array Except Self

摘要: if concerned with 0, check the elements on the side first, the situation in the middle is handled Given an array nums of n integers where n > 1, retur 阅读全文

posted @ 2018-08-17 08:11 猪猪🐷 阅读(121) 评论(0) 推荐(0)

158. Read N Characters Given Read4 II - Call multiple times

摘要: The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it retu 阅读全文

posted @ 2018-08-17 00:13 猪猪🐷 阅读(139) 评论(0) 推荐(0)

Task schedule

摘要: Task schedule https://leetcode.com/problems/task-scheduler/solution/ https://github.com/tongzhang1994/Facebook-Interview-Coding/blob/master/Task%20schedule%20with%20cool%20down%20time.java Given ... 阅读全文

posted @ 2018-08-17 00:12 猪猪🐷 阅读(468) 评论(0) 推荐(0)

157. Read N Characters Given Read4

摘要: The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it retu 阅读全文

posted @ 2018-08-17 00:12 猪猪🐷 阅读(161) 评论(0) 推荐(0)

Sparse Matrix Multiplication

摘要: Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is equal to B's row number. Example: 阅读全文

posted @ 2018-08-17 00:11 猪猪🐷 阅读(165) 评论(0) 推荐(0)

Sparse vector Multiplication

摘要: Sparse vector Multiplication https://github.com/tongzhang1994/Facebook-Interview-Coding/blob/master/Sparce%20Matrix%20Multiplication.java public class Solution {//assume inputs are like {{2, 4}... 阅读全文

posted @ 2018-08-17 00:10 猪猪🐷 阅读(213) 评论(0) 推荐(0)

Print All Paths in a 2D Board

摘要: Print All Paths in a 2D Board public class Solution { private int m; private int n; public void printAllPath(char[][] grid) { int count=0; m=grid.length; if(m==0)... 阅读全文

posted @ 2018-08-17 00:09 猪猪🐷 阅读(126) 评论(0) 推荐(0)

2018年8月16日

314. Binary Tree Vertical Order Traversal

摘要: use two stacks 阅读全文

posted @ 2018-08-16 23:57 猪猪🐷 阅读(97) 评论(0) 推荐(0)

108. Convert Sorted Array to balanced Binary Search Tree

摘要: 带返回值的 recursion Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced 阅读全文

posted @ 2018-08-16 23:54 猪猪🐷 阅读(85) 评论(0) 推荐(0)

binary search tree to sorted double linked list (not circular) (okay)

摘要: TreeNode head = null; TreeNode prev = null; public void inOrder(TreeNode root){ if(root == null) return; inOrder(root.left); if(prev == null){ head = root; }else{ prev.right = root... 阅读全文

posted @ 2018-08-16 23:52 猪猪🐷 阅读(129) 评论(0) 推荐(0)

109. Convert Sorted List to Binary Search Tree

摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced bina 阅读全文

posted @ 2018-08-16 23:51 猪猪🐷 阅读(96) 评论(0) 推荐(0)

Convert Sorted double linked List to Binary Search Tree

摘要: 把自己写的solution 1 和 闫老师写的solution2 都弄懂,会写。 bst变double linked list。recursion秒了,然后第一个follow up是把双链表变回去,要求balance。第二个follow up是在牺牲空间复杂度的情况下如何优化时间,想了个时间O(n) 阅读全文

posted @ 2018-08-16 23:49 猪猪🐷 阅读(180) 评论(0) 推荐(0)

previous and next permutation

摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib 阅读全文

posted @ 2018-08-16 23:45 猪猪🐷 阅读(169) 评论(0) 推荐(0)

301. Remove Invalid Parentheses

摘要: 301. Remove Invalid Parentheses Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters oth... 阅读全文

posted @ 2018-08-16 23:44 猪猪🐷 阅读(188) 评论(0) 推荐(0)

2018年8月11日

209. Minimum Size Subarray Sum

摘要: Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't 阅读全文

posted @ 2018-08-11 05:15 猪猪🐷 阅读(120) 评论(0) 推荐(0)

159. Longest Substring with At Most Two Distinct Characters

摘要: Given a string s , find the length of the longest substring t that contains at most 2 distinct characters. Example 1: Example 2: 阅读全文

posted @ 2018-08-11 04:55 猪猪🐷 阅读(120) 评论(0) 推荐(0)

find the length of shortest path between two nodes in a tree

摘要: https://www.geeksforgeeks.org/shortest-path-between-two-nodes-in-array-like-representation-of-binary-tree/ 阅读全文

posted @ 2018-08-11 04:53 猪猪🐷 阅读(84) 评论(0) 推荐(0)

236. Lowest Common Ancestor of a Binary Tree

摘要: time complexity is O(n) Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA 阅读全文

posted @ 2018-08-11 04:52 猪猪🐷 阅读(104) 评论(0) 推荐(0)

199. Binary Tree Right Side View

摘要: ( bfs is easy, instead use preorder dfs right first and then left) Given a binary tree, imagine yourself standing on the right side of it, return the 阅读全文

posted @ 2018-08-11 04:39 猪猪🐷 阅读(107) 评论(0) 推荐(0)

257 binary tree paths

摘要: https://github.com/tongzhang1994/Facebook-Interview-Coding/blob/master/257.%20Binary%20Tree%20Paths.java Given a binary tree, return all root-to-leaf 阅读全文

posted @ 2018-08-11 04:38 猪猪🐷 阅读(104) 评论(0) 推荐(0)

103. Binary Tree Zigzag Level Order Traversal

摘要: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and 阅读全文

posted @ 2018-08-11 04:33 猪猪🐷 阅读(105) 评论(0) 推荐(0)

求只包含素数的数组里面所有元素所有可能的乘积

摘要: not tested yet 阅读全文

posted @ 2018-08-11 04:30 猪猪🐷 阅读(310) 评论(0) 推荐(0)

permutation II

摘要: example: 1 1 1 2 for the first pos, we can chose 1 and 2 , skip the two 1s in the middle , the way we skip these 1s is within the for loop, we only ad 阅读全文

posted @ 2018-08-11 04:29 猪猪🐷 阅读(179) 评论(0) 推荐(0)

653 two sum iv - input is a bst

摘要: 653 two sum iv - input is a bst Approach #1 Using HashSet[Accepted] The simplest solution will be to traverse over the whole tree and consider every p 阅读全文

posted @ 2018-08-11 04:15 猪猪🐷 阅读(133) 评论(0) 推荐(0)

133. Clone Graph

摘要: Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph contains a label (int) and a list (List[UndirectedGraphNode 阅读全文

posted @ 2018-08-11 03:54 猪猪🐷 阅读(120) 评论(0) 推荐(0)

Find Shortest distance from a guard in a Bank.

摘要: Given a matrix that is filled with ‘O’, ‘G’, and ‘W’ where ‘O’ represents open space, ‘G’ represents guards and ‘W’ represents walls in a Bank. Replac 阅读全文

posted @ 2018-08-11 03:51 猪猪🐷 阅读(386) 评论(0) 推荐(0)

top k closest points to origin, k closest points to <0,0,0>

摘要: 大班文档有java solution 强化 5 x.y z is similar 阅读全文

posted @ 2018-08-11 03:47 猪猪&#128055; 阅读(157) 评论(0) 推荐(0)

120. Triangle

摘要: 120. Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], ... 阅读全文

posted @ 2018-08-11 03:41 猪猪&#128055; 阅读(163) 评论(0) 推荐(0)

377. Combination Sum IV

摘要: 377. Combination Sum IV Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target. Example: nums = [1, 2, ... 阅读全文

posted @ 2018-08-11 03:40 猪猪&#128055; 阅读(126) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 12 13 14 15 下一页

导航