![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
文章平均质量分 55
qbt4juik
这个作者很懒,什么都没留下…
展开
-
Dynamic Programming for Brother Du
Let's see an example to understand what is dynamic programming. Alice is located in the North-West (Top-Left) block of her city, which has the form of a gird of NxNNxN blocks. On each block the原创 2016-02-05 11:33:18 · 602 阅读 · 1 评论 -
【Leetcode】Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain leading or trailing spaces and the words are alway原创 2016-04-01 03:09:30 · 402 阅读 · 0 评论 -
Greatest Common Divisor 最大公约数 O(n)
不废话,直接上代码 package testAndfun; //great common divisor public class gcd { public static void main(String[] args){ gcd g = new gcd(); int[] input = {16,64,26,78}; System.out.println(g.getGCD(inp原创 2016-02-04 07:13:04 · 518 阅读 · 0 评论 -
LFU Cache
与LRU不同LFU关注与出现的频率,然后想自己写一个,区别在于: 如果是LRU,假如capacity是2:输入是ABCBBBBBBCAA,那么最后会剩下的是C和A在缓存里。 但是如果是LFU,capacity也是2:输入是ABCBBBBBBCAA,最后剩下的是[A,B],因为B出现的频率高。也就是说就算之前因为频率低被淘汰了,后面又出现了也要再回来。 所以我想的设计方案是,整个LFUCach原创 2016-02-04 06:03:01 · 2283 阅读 · 0 评论 -
Merge Two Linked List
Given 1-3-5-6-8, 2-4-9, you want to merge to 1-2-3-4-5-6-8-9. My solution is very naive solution that actually build a new linkedlist, require space O(n). public ListNode mergeTwoLists(ListNode l1,原创 2016-02-03 23:36:34 · 322 阅读 · 0 评论 -
K Closest Points
Given (0,0) as the centre and an array containing pair of coordinate such that (1,1) (-2,4) (3,4) (-11,5) ... (x,y). If ask you return k closest points, how would you do it? import java.util.原创 2016-02-03 12:21:32 · 495 阅读 · 0 评论 -
Reverse Half LinkedList
1-2-3-4-5-6 into 1-2-3-6-5-4 or 1-2-3-4-5 into 1-2-5-4-3 I took advantage of reversing a linkedlist. I provided main func and prinf func. package testAndfun; public class reverseHalfLinkedList {原创 2016-02-03 11:08:07 · 336 阅读 · 0 评论 -
A few very crucial DATA STRUCTURE
0. queue 这次好好看之前,我觉得我一直对queue简直就是一知半解。首先queue与stack并不是对称的,在java里。stack可以直接new, 而queue只是一个接口,上张图就明白了。 一眼明了,我觉得要想闹明白,最好就是去看源码,去看从最上面怎么一步一步继承下来的,每一个数据结构自己的特点又都是什么。 对于queue的方法,这里有必要讲一下: 这里简单对其重原创 2016-02-03 08:22:11 · 351 阅读 · 0 评论 -
【Leetcode】Binary Tree Level Order Traversal I/II AND Binary Tree Zigzag Level Order Traversal
看这篇文章的朋友们建议先看一下我的上一篇文章,讲的非常清楚我们面对“level”的问题的时候我们要怎么写代码处理,再强调一次 每次BFS在里面的时候,一定要手写int size= queue.size(),因为queue一直是dynamic的!!! ok,第一二问的Binary Tree Level Order Traversal 其实是一样的。 一、 Given a binary原创 2016-02-12 07:45:53 · 332 阅读 · 0 评论 -
【Leetcode】Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary tree, 1原创 2016-02-12 06:09:57 · 299 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node I, II
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node.原创 2016-02-09 04:36:04 · 288 阅读 · 0 评论 -
【Leetcode】Two Problems: Convert Sorted Array/List to Binary Search Tree
First let's try easier one: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. The logic is very simple: Every time you find the middle element and p原创 2016-02-08 07:56:11 · 470 阅读 · 0 评论 -
【Leetcode】Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. ———————————————————————— 最近准备开始原创 2016-02-08 07:11:50 · 307 阅读 · 0 评论 -
【Leetcode】Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /** * Def原创 2016-04-01 09:39:00 · 368 阅读 · 0 评论