
算法设计
文章平均质量分 51
Aaron92
一名未入门的程序猿
展开
-
小白笔记------------------------------------------leetcode(17. Letter Combinations of a Phone Number)
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is giv...原创 2018-07-21 17:09:21 · 465 阅读 · 0 评论 -
小白笔记---------------------------------leetcode(101. Symmetric Tree )
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3B原创 2017-11-30 16:28:26 · 277 阅读 · 0 评论 -
小白笔记-------------------------------leetcode(11. Container With Most Water )
Given n non-negative integers a1, a2, ...,an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of linei is at (i, ai) and (i, 0). Find原创 2017-11-09 11:27:01 · 256 阅读 · 0 评论 -
小白笔记--------------------------leetcode 34. Search for a Range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the ta原创 2017-08-18 11:06:01 · 282 阅读 · 0 评论 -
小白笔记----------------------------------leetcode(22. Generate Parentheses )
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.这道算法涉及到什么卡特兰数,我们把他考虑成一个树的剪枝问题,确定剪枝的条件,就是剩余的左括号树一定大于右括号数。本文算法,采纳自这篇大牛博客,详细解释,请跳转http://blo原创 2017-08-03 11:09:24 · 299 阅读 · 0 评论 -
小白笔记----------------------------------------leetcode 3. Longest Substring Without Repeating Characte
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with原创 2017-08-08 10:38:49 · 280 阅读 · 0 评论 -
小白笔记--------------------leetcode27. Remove Element
public class Solution { public int removeElement(int[] nums, int val) { int count = 0; int result = 0; int s = nums.length; int j = 0; for(int i = 0 ; i < n原创 2017-07-31 18:14:46 · 278 阅读 · 0 评论 -
小白笔记-----------------------------leetcode53. Maximum Subarray
public class Solution { public int maxSubArray(int[] nums) { int count = 0; int max = nums[0]; for(int i = 0;i < nums.length;i++){ count = nums[i];原创 2017-07-30 18:21:40 · 273 阅读 · 0 评论 -
小白笔记---------------------(算法总结)(1)
小白笔记———————(算法总结)(1)二分搜索算法解决问题:从数组中查找已知存在的数的位置前提条件:一个已经排好序的整型数组一般解决方式:遍历数组,找到第一次出现的要找的数,返回它的位置使用价值:除非特别指定用二分搜索算法,大部分情况下都能用一层循环解决求众数解决问题:求整型数组中出现次数最多的数一般解决方法:用一个数组记录每个数出现的次数,遍历这个数组找到最大值,返回原数组该位置的原创 2017-06-20 17:10:47 · 406 阅读 · 0 评论 -
小白笔记--------------------------leetcode(20. Valid Parentheses )
Given a string containing just the characters '(', ')','{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid b原创 2017-04-06 11:28:20 · 296 阅读 · 0 评论 -
小白笔记----------------------leetcode(9. Palindrome Number)
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting th原创 2016-12-26 11:05:50 · 353 阅读 · 0 评论 -
小白笔记------------------------leetcode(7. Reverse Integer)
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding.原创 2016-12-24 14:36:35 · 401 阅读 · 0 评论 -
小白笔记-----------------------leetcode(8. String to Integer (atoi) )
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input case原创 2016-12-23 23:19:22 · 316 阅读 · 0 评论 -
小白笔记----------------------------------------leetcode(39. Combination Sum )
Given a set of candidate numbers (C)(without duplicates) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen原创 2017-11-22 11:25:46 · 358 阅读 · 0 评论 -
小白笔记----------------------------------------leetcode(40. Combination Sum II )
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used once in the combinatio原创 2017-11-22 17:19:24 · 268 阅读 · 0 评论 -
小白笔记-----------------------------------------leetcode(190. Reverse Bits)
Reverse bits of a given 32 bits unsigned integer.Example:Input: 43261596 Output: 964176192 Explanation: 43261596 represented in binary as 00000010100101000001111010011100, return ...原创 2018-07-07 21:46:24 · 250 阅读 · 0 评论 -
小白笔记-------------------------------------------------(leetcode:24. Swap Nodes in Pairs)
Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only ...原创 2018-07-16 11:23:10 · 711 阅读 · 0 评论 -
小白笔记-----------------------------------------------------leetcode(257. Binary Tree Paths)
Given a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.Example:Input:1 / \ 2 3 \ 5Output: [“1->2->5”, “1->3”]Explanation: All roo...原创 2018-06-24 15:16:14 · 204 阅读 · 0 评论 -
小白笔记------------------------------leetcode(160. Intersection of Two Linked Lists)
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ ...原创 2018-06-08 20:43:26 · 299 阅读 · 0 评论 -
小白笔记-----------------leetcode(111. Minimum Depth of Binary Tree && 110. Balanced Binary Tree)
110: Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of every node never...原创 2018-05-07 14:47:03 · 239 阅读 · 0 评论 -
小白笔记---------------------------------------------leetcode(118. Pascal's Triangle)
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Example:Input: 5 Output: ...原创 2018-05-09 22:53:41 · 234 阅读 · 0 评论 -
小白笔记-------------------------------leetcode(141. Linked List Cycle)
Given a linked list, determine if it has a cycle in it. 判断一个链表是否有环,参考了网上的方法,设计一个快指针和慢指针,让它们互相追,有点像火车相遇问题,哈哈,代码如下,这里主要容易出现空指针问题,需要注意循环条件,另外将要入职华为了,真的开始做程序员,保持初心吧,但愿coding会一直是我的乐趣,而不是变成工作的烦恼。/** ...原创 2018-04-11 10:55:42 · 256 阅读 · 0 评论 -
小白笔记---------------------------------leetcode(67. Add Binary )
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".本来这道题,我想直接用long的parseInt方法,然后发现字符串太长了超出了Long的范围,之后看了大家的答题经验之后,发现应该一位一位地处理,模仿原创 2017-11-25 14:46:45 · 292 阅读 · 0 评论 -
小白笔记-------------------------------------leetcode(136. Single Number )
iven an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra原创 2017-12-04 21:03:01 · 253 阅读 · 0 评论 -
小白笔记---------------------------------leetcode(70. Climbing Stairs )
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive原创 2017-11-24 21:43:32 · 361 阅读 · 0 评论 -
小白笔记----------------------------------------------leetcode(107. Binary Tree Level Order Traversal I)
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,15,原创 2017-12-03 20:58:09 · 283 阅读 · 0 评论 -
小白笔记---------------------------------leetcode(48. Rotate Image )
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix d原创 2017-11-23 21:14:08 · 302 阅读 · 0 评论 -
小白笔记-----------------------leetcode(28. Implement strStr())
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这一次用java写的,确实比用c简单了许多。。。代码入下:public class Solution { public in原创 2016-12-15 19:29:57 · 339 阅读 · 0 评论 -
小白笔记---------------------------leetcode(203. Remove Linked List Elements )
203. Remove Linked List Elements Total Accepted: 89567Total Submissions: 291809Difficulty: EasyContributors: Admin Remove all elements from a linked list of integers that h原创 2016-11-28 11:26:29 · 306 阅读 · 0 评论 -
小白笔记------------leetcode(204. Count Primeszhe)
Description:Count the number of prime numbers less than a non-negative number, n.这一题用常规的判断是否是质数的方法行不通,我尝试过,最后是没有结果,这里引用一个古老的算法,下面一段复制粘贴——————————————————————我们知道2是最小的质数,那么2的倍数均不为质数(因为它们可以分解为一个原创 2016-07-24 10:17:45 · 478 阅读 · 0 评论 -
小白笔记----------------判断一个数是不是某个数的次方
首先,这个数要非0 ,其次这个数对某个数的取余一定为为0,做如下的循环就能够判断了while(num && num%s == 0){ num /= s;}return num==1;//这个1可能根据s的正负变化,这里默认s 为正数原创 2016-07-23 14:49:23 · 526 阅读 · 0 评论 -
小白笔记-------------------二分搜索算法(再刷一遍)
374. Guess Number Higher or LowerWe are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong,原创 2016-07-22 19:40:52 · 661 阅读 · 0 评论 -
小白笔记------------------二分搜索算法2.0
之前没试验过多种情况,这个应该是精简可行的/******************************************************* Author : Aaron92* Date : 2016-06-12 08:57* Filename : Binarysearch.c* Description : ******************原创 2016-06-12 09:53:23 · 501 阅读 · 0 评论 -
小白笔记------------------最小m段和问题
最近在看动态规划法,对状态转移方程总是写不出来例如今天这个问题:这个问题怎么才能抽象出状态转移方程呢?我们考虑将5个数分成3段的情形,首先考虑分成1段的时候,一个数只能分成1个段,则f[1][1] = a[1],如果是两个数呢,两个数可以分成1段则,f[2][1] = a[1] + a[2],由此易得对于i个数,f[i][1] = a[1] + a[2] + ...+a[i]。接着考虑分成原创 2016-06-07 21:47:41 · 2586 阅读 · 1 评论 -
小白笔记--------------------矩阵连乘问题(求怎么加括号运算量最小)
#include#include#includevoid print(int(*n)[7]);void MatrixChain(int*p,int n,int(*m)[7],int(*s)[7]);main(int argc, char** argv){ int a1[30][35],a2[35][15],a3[15][5],a4[5][10],a5[10][20],a6[20]原创 2016-04-02 15:08:07 · 1465 阅读 · 0 评论 -
小白笔记-----------------------迭代回溯
讨论装载问题: 有一批n个集装箱装入载重量为c的轮船,找出最多能装多少?解:一般回溯法思想,这是个子集数问题,用递归比较好写,然而不用递归怎么写呢?这里用到了迭代回溯的思想。/******************************************************* Author : Aaron92* Date : 2016-05-原创 2016-05-12 19:20:48 · 664 阅读 · 0 评论 -
小白笔记-------------------------最大团问题
网上已经有很多关于最大团的文章了,这里主要还是要用到子集树的思路,另外就是判定条件要特别注意!另外这个问题特别出名而且实用,需要多注意。/******************************************************* Author : Aaron92* Date : 2016-05-23 16:54* Filename : MaxC原创 2016-05-24 16:00:13 · 622 阅读 · 0 评论 -
小白笔记-----------------------符号三角形问题(回溯法---子集树)
问题描述:确定第一行符号,如正负号,第二行,相同符号则显示正号,不同则显示负号,a[j][i] = !(a[j-1][i]^a[j-1][i+1]),满足如下公式。理解:在用回溯法解题时,可以考虑两种思路,分别是子集树,和排列树思路。排列树在一些情况下,难以适用,如解结构不同时,而子集树,则相当于穷举,但不是简单的穷举,而是在穷举的过程中不断的裁剪废解。框架:void back原创 2016-05-24 15:56:51 · 1641 阅读 · 0 评论 -
小白笔记--------------------构造最长公共子序列
/******************************************* Name: LCSLengh* Description: Firgure out the longest same part of two* different alphabetic strings* Author: Aaron92* Time: 2016/4/* Modified原创 2016-04-06 13:28:02 · 528 阅读 · 0 评论 -
小白笔记---------------------自然合并排序算法(感谢bob的指导)
import java.awt.List;import java.util.LinkedList;import java.util.Scanner;public class Naturesort { public static void main(String[] args) { int[] a = read(); print(a); int[] b = getCo原创 2016-03-25 00:18:54 · 506 阅读 · 0 评论