云飞扬的个人博客 云飞扬的个人博客
Tags Archives Links
  • 开始使用
  • 我的开源
  • Tags
  • Archives
  • Links
  • Search
  • RSS
题目 Given two binary strings, return their sum (also a binary string). The input strings are bothnon-emptyand contains only characters1or 0.

[67] Add Binary

LeetCode
题目 Given anon-emptyarray of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself. Example 1: Input: [1,2,3] Output: [1,2,4] Explanation: The array represents the integer 123. Example 2: Input: [4,3,2,1] Output: [4,3,2,2] Explanation: The array repr....

[66] Plus One

LeetCode
题目 Given a string_s_consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.

[58] Length of Last Word

LeetCode
题目 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. 解法 一 思路 遍历数组,同时计算子数组和,当和小于0时重置为0 代码

[53] Maximum Subarray

LeetCode
定义 装饰者模式: 动态的将责任附加到对象上。若要扩展功能,装饰者提供了比继承更有弹性的替代方案。 Java实现 背景 制作咖啡时,不同的调料搭配不同的咖啡,动态的计算价钱。 超类 饮料类 public abstract class Beverage { String description = "Unknown Beverage"; public String getDescription() { return description; } /** * 功能描述: 价钱 * * @return double * @author liyf */ public abstract double cost(); } 具体咖啡类 需要为具体的咖啡设置描述,而且还必须实现cost()方法 浓缩咖啡 public class Espresso extends Beverage { public Espresso() { description = "Espresso"; } @Override public double cost() { return 1.99; } } 综合咖啡 pub....

装饰者模式

设计模式
题目 The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1is read off as"one 1"or11. 11is read off as"two 1s"or21. 21is read off as"one 2, thenone 1"or1211. Given an integer_n_ where 1 ≤_n_≤ 30, generate the_n_thterm of the count-and-say sequence. Note: Each term of the sequence of integers will be represented as a string. Example 1: Input: 1 Output: "1" Example 2: Input: 4 Output: "1211" 解法 一 思路 遍历时使用变量记录当前数字及次数....

[38] Count and Say

LeetCode
观察者模式 定义了对象之间的一对多依赖,这样一来,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新。

观察者模式

设计模式
题目 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2 Example 2: Input: [1,3,5,6], 2 Output: 1 Example 3: Input: [1,3,5,6], 7 Output: 4 Example 4: Input: [1,3,5,6], 0 Output: 0 解法 一:暴力 思路 for循环即可 代码 二:二分查找 思路 使用二分查找 代码

[35] Search Insert Position

LeetCode
设计原则 找出应用中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起。 针对接口编程,而不是针对实现编程。 针对接口编程真正的意思时"针对超类型(supertype)编程" 多用组合,少用继承 为了交互对象之间的松耦合设计而努力。 松耦合的设计之所以能让我们建立有弹性的OO系统,能够应对变化,是因为对象之间的互相依赖降到了最低。 类应该对扩展开放,对修改关闭 依赖倒置原则:要依赖抽象,不要依赖具体类。 指导方针: 变量不可以持有具体类的引用 不要让类派生自具体类 不要覆盖基类中已实现的方法 应尽量达到这个原则,而不是随时都要遵循这个原则

Head First 设计原则

设计模式
1 2 3 4 5 6 7
我的开源 RSS 开始使用
93814690 - 记录精彩的程序人生

Open Source, Open Mind,
Open Sight, Open Future!
分类

Java     LeetCode     Linux     Node.js    
63 文章
16880 浏览     2 当前访客
© 2025 云飞扬的个人博客