- 博客(58)
- 收藏
- 关注
转载 leetcode 219
219. Contains Duplicate IIGiven an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and theabsolutedifferen...
2017-02-05 16:30:00
88
转载 策略模式
它定义了一系列的算法,并将每个算法封装起来,而且使他们还可以相互替换。策略模式让算法的变化不会影响到使用算法的客户。优点: 1)简化了单元测试,因为每个算法都有自己的类,可以通过自己的接口单独测试。 2)避免程序中使用多重条件转移语句,使系统更灵活,并易于扩展。 3)遵守大部分GRASP原则和常用设计原则,高内聚、低耦合。缺点: 1)因为每个具体策略类都会...
2017-01-21 21:28:00
100
转载 简单工厂模式(静态工厂方法模式)
以计算器程序为例:只需输入运算符号,程序就实例化出合适的对象。通过多态,返回父类的方式实现了计算器的结果。1)静态工厂方法统一管理对象的创建。 静态工厂方法通过传入的参数判断决定创建哪一个产品的实例,封装了对象的创建,客户端只管消费,实现了对责任(模块)的分割。2)静态工厂方法推迟了产品的实例化。 通过XML配置文件就能改变具体创建的产品实例,修改为其他的产品实例,代...
2017-01-21 18:56:00
121
转载 leetcode 217
217. Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should re...
2016-12-18 20:50:00
95
转载 leetcode 206
206. Reverse Linked ListReverse a singly linked list.翻转一个单链表。代码如下: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *n...
2016-11-14 16:02:00
66
转载 leetcode 205
205. Isomorphic StringsGiven two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a character ...
2016-11-14 10:58:00
96
转载 leetcode 202
202. Happy NumberWrite an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by ...
2016-11-09 11:41:00
89
转载 leetcode 198
198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of the...
2016-11-09 11:05:00
99
转载 leetcode 191
191. Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has bina...
2016-11-09 10:13:00
144
转载 leetcode 190
190. Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return 964176192 (represented ...
2016-11-09 10:05:00
91
转载 leetcode 189
189. Rotate ArrayRotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].将数组向右旋转k位。代码如下: 1 ...
2016-11-08 17:25:00
76
转载 leetcode 172
172. Factorial Trailing ZeroesGiven an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.计算出n!中尾部0的个数。1*2*3*......*n中0的个数由2和...
2016-11-08 16:36:00
51
转载 leetcode 171
171. Excel Sheet Column NumberRelated to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> ...
2016-11-08 11:45:00
81
转载 leetcode 169
169. Majority ElementGiven an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty a...
2016-11-08 10:58:00
77
转载 win10内网外网智能访问
当电脑同时连接有线和WiFi时(有线连接为内网,WiFi为外网),会出现内网和外网内容无法同时访问的情况。本方法实现内网和外网的同时访问。第一步:输入指令 “route print” 查看路由表;第二步:输入“route delete 0.0.0.0” 删除默认路由;第三步:输入“route add 10.0.0.0 mask 255.0.0.0 10....
2016-10-23 10:01:00
399
转载 leetcode 168
168. Excel Sheet Column TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... ...
2016-10-11 22:29:00
287
转载 leetcode 165
165. Compare Version NumbersCompare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1<version2return -1, otherwise return 0.You may assume that t...
2016-10-11 19:40:00
162
转载 leetcode 160
160. Intersection of Two Linked ListsWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: ...
2016-10-11 10:33:00
76
转载 leetcode 155
155. Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of ...
2016-10-11 09:54:00
67
转载 leetcode 141
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断一个单链表中是否存在环。不利用额外的空间。思路:初始两个指针都指向头结点,一个指针每次移动一次,另一个指针每次...
2016-10-10 21:22:00
72
转载 leetcode 137
137. Single Number IIGiven an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you ...
2016-10-10 20:59:00
63
转载 leetcode 136
136. Single NumberGiven an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement...
2016-10-05 17:27:00
62
转载 leetcode 125
125. Valid PalindromeGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome....
2016-10-01 16:49:00
78
转载 leetcode 121
121. Best Time to Buy and Sell StockSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, ...
2016-09-30 11:27:00
75
转载 leetcode 119
119. Pascal's Triangle IIGiven an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extr...
2016-09-29 21:19:00
54
转载 leetcode 118
118. Pascal's TriangleGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]...
2016-09-28 11:26:00
55
转载 leetcode 112
112. Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below bi...
2016-09-28 10:24:00
114
转载 leetcode 111
111. Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node....
2016-09-27 22:32:00
70
转载 leetcode 110
110. Balanced Binary TreeGiven 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 subt...
2016-09-13 20:44:00
77
转载 leetcode 107
107. Binary Tree Level Order Traversal IIGiven a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For e...
2016-09-13 16:58:00
147
转载 leetcode 104
104. Maximum Depth of Binary TreeGiven 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-09-13 12:01:00
66
转载 leetcode 102
102. Binary Tree Level Order TraversalGiven a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree[3,9,2...
2016-09-13 11:18:00
61
转载 leetcode 101
101. Symmetric TreeGiven 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 / \ ...
2016-09-12 11:38:00
72
转载 leetcode 100
100. Same TreeGiven 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 v...
2016-09-11 11:08:00
57
转载 leetcode 88
88. Merge Sorted ArrayGiven two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is greater or equa...
2016-09-11 10:34:00
62
转载 leetcode 83
83. Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1-&...
2016-09-09 22:15:00
83
转载 leetcode 70
70. Climbing StairsYou are climbing a stair case. It takesnsteps 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?此题为典型的...
2016-09-09 21:58:00
52
转载 leetcode 67
67. Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".两个字符串存储二进制数,进行二进制加法,返回相加之后的结果。代码如下: 1 class Solution {...
2016-09-09 16:48:00
59
转载 leetcode 66
66. Plus OneGiven a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.一个非负整...
2016-09-09 11:48:00
71
转载 leetcode 58
58. Length of Last WordGiven a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, re...
2016-09-09 11:16:00
72
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人