随笔分类 -  Algorithms

上一页 1 ··· 3 4 5 6 7 8 9 下一页
摘要:Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive intege 阅读全文
posted @ 2019-03-08 02:56 Zhentiw 阅读(372) 评论(0) 推荐(0)
摘要:Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string 阅读全文
posted @ 2019-03-07 04:28 Zhentiw 阅读(532) 评论(0) 推荐(0)
摘要:// Code goes here function countNegative (M, n, m) { count = 0; i = 0; j = m - 1; while (j >=0 && i < n) { if (M[i][j] < 0) { count += (j+1) i += 1; } else { j... 阅读全文
posted @ 2019-03-06 14:25 Zhentiw 阅读(148) 评论(0) 推荐(0)
摘要:Let's say we are given an array: We want to get K = 3 smallest items from the array and using Max heap data structure. So this is how to think about i 阅读全文
posted @ 2019-03-05 22:38 Zhentiw 阅读(186) 评论(0) 推荐(0)
摘要:Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original ar 阅读全文
posted @ 2019-03-05 02:35 Zhentiw 阅读(127) 评论(0) 推荐(0)
摘要:For example there is a staricase N = 3 | | | | | | | | | | There is N = 3 staricase, for each step, you can either take {1 or 2} step at a time. So as 阅读全文
posted @ 2019-03-05 01:36 Zhentiw 阅读(189) 评论(0) 推荐(0)
摘要:For example we have 'a' -> 1 'b' -> 2 .. 'z' -> 26 By given "12", we can decode the string to give result "ab" or 'L', 2 ways to decode, your function 阅读全文
posted @ 2019-03-04 01:58 Zhentiw 阅读(311) 评论(0) 推荐(0)
摘要:Given a string, find the longest subsequence consisting of a single character. Example: longest("ABAACDDDBBA") should return {'D': 3}. 阅读全文
posted @ 2019-02-28 03:04 Zhentiw 阅读(198) 评论(0) 推荐(0)
摘要:Each row and each column are already SORTED in the given matrix! 阅读全文
posted @ 2019-02-24 20:56 Zhentiw 阅读(155) 评论(0) 推荐(0)
摘要:For a given array, we try to find set of pair which sums up as the given target number. For example, we are given the array and target as: We should b 阅读全文
posted @ 2019-02-18 05:10 Zhentiw 阅读(461) 评论(0) 推荐(0)
摘要:About how to traverse binary tree, can refer this post. 阅读全文
posted @ 2019-02-16 17:00 Zhentiw 阅读(258) 评论(0) 推荐(0)
摘要:For example we have: We want to get: Requirement: You can only do in array swap, you cannot create a new array. The way to do it: 1. Reverse whole str 阅读全文
posted @ 2019-02-15 19:56 Zhentiw 阅读(155) 评论(0) 推荐(0)
摘要:vThere are three ways to solve Fibonacci problem 'First Recursion approach: As we can see to calculate fib(5), we need to calculate fib(3) twice and f 阅读全文
posted @ 2019-02-12 19:02 Zhentiw 阅读(280) 评论(0) 推荐(0)
摘要:Q1: Find the smallest value from array: O(n), cannot be improved anymore, because we have to loop though the array once. Q2: Find 2nd smallest value, 阅读全文
posted @ 2019-02-06 03:03 Zhentiw 阅读(223) 评论(0) 推荐(0)
摘要:A balanced binary tree is something that is used very commonly in analysis of computer science algorithms. In this lesson we cover how to determine th 阅读全文
posted @ 2019-01-30 16:03 Zhentiw 阅读(234) 评论(0) 推荐(0)
摘要:Shuffling is a common process used with randomizing the order for a deck of cards. The key property for a perfect shuffle is that each item should hav 阅读全文
posted @ 2019-01-29 19:59 Zhentiw 阅读(287) 评论(0) 推荐(0)
摘要:One integer takes 32bit in memory, 1 byte = 8bits, therefore one integer takes 4 bytes. Now let's assume we have an array: [1,2,3] 4bytes . 4bytes . 4 阅读全文
posted @ 2019-01-08 03:50 Zhentiw 阅读(105) 评论(0) 推荐(0)
摘要:Naive solution for this problem would be caluclate all the possible combinations: The maximum subarray problem is one of the nicest examples of dynami 阅读全文
posted @ 2019-01-06 03:57 Zhentiw 阅读(221) 评论(0) 推荐(0)
摘要:The median maintenance problem is a common programming challenge presented in software engineering job interviews. In this lesson we cover an example 阅读全文
posted @ 2019-01-04 20:13 Zhentiw 阅读(506) 评论(0) 推荐(0)
摘要:Source, git Heap is a data structure that can fundamentally change the performance of fairly common algorithms in Computer Science. The heap data stru 阅读全文
posted @ 2019-01-02 20:26 Zhentiw 阅读(881) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 下一页