随笔分类 -  Algorithm

摘要:涉及队列、栈的运用。Java中队列可以用:Queue q = new LinkedList();来声明,其主要的方法有:poll(),peak(),offer(),clear(),size()等。Java中栈可以用:Stack s = new Stack();来声明,其主要方法有:push(),pe... 阅读全文
posted @ 2015-09-18 01:47 CHEN0958 阅读(279) 评论(0) 推荐(0)
摘要:对表达式求值。已知运算符只有加减乘除,无负数,结果也不是负数。(类似逆波兰法的算法思路)思想:对数字只要入栈就可以,需要时拿出来计算。对符号,有几种情况:(1)新符号加入前符号栈中还没有符号,则直接入栈;(2)新符号是加减运算,则将之前符号栈中的符号全部拿出来计算,每次消耗1个符号,2个数字,再将得... 阅读全文
posted @ 2015-09-18 00:49 CHEN0958 阅读(347) 评论(0) 推荐(0)
摘要:C++中由于有指针的存在,可以让二叉树节点指针的指针作为插入函数的实参,在函数体内通过*操作实现对真实节点指针、节点左孩子指针、节点右孩子指针的改变,这样很容易使用递归将大树问题转化到小树问题。但在JAVA中,由于没有指针只有引用,如果需要递归实现二叉树的元素插入,需要对节点进行包装,同时由于递归时... 阅读全文
posted @ 2015-09-16 02:04 CHEN0958 阅读(2468) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr... 阅读全文
posted @ 2015-09-15 16:15 CHEN0958 阅读(161) 评论(0) 推荐(0)
摘要:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6... 阅读全文
posted @ 2015-09-15 14:49 CHEN0958 阅读(170) 评论(0) 推荐(0)
摘要:二分查找代码://============================================================================// Name : BinarySearch.cpp// Author : Danny// Version... 阅读全文
posted @ 2015-05-24 01:49 CHEN0958 阅读(177) 评论(0) 推荐(0)
摘要:快速排序算法实现代码://============================================================================// Name : QuickSort.cpp// Author : Danny// Versio... 阅读全文
posted @ 2015-05-24 01:31 CHEN0958 阅读(213) 评论(0) 推荐(1)
摘要:Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniq... 阅读全文
posted @ 2015-03-22 18:12 CHEN0958 阅读(383) 评论(0) 推荐(0)
摘要:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321click to show spoilers.Have you thought about this?Here are som... 阅读全文
posted @ 2015-03-22 01:44 CHEN0958 阅读(118) 评论(0) 推荐(0)
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2015-03-22 00:56 CHEN0958 阅读(121) 评论(0) 推荐(0)
摘要:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa... 阅读全文
posted @ 2015-03-21 23:04 CHEN0958 阅读(155) 评论(0) 推荐(0)
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ... 阅读全文
posted @ 2015-03-21 22:00 CHEN0958 阅读(129) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文
posted @ 2015-03-21 20:12 CHEN0958 阅读(131) 评论(0) 推荐(0)
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2015-03-21 18:24 CHEN0958 阅读(117) 评论(0) 推荐(0)
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2015-03-21 16:19 CHEN0958 阅读(120) 评论(0) 推荐(0)