Skip to content

Instantly share code, notes, and snippets.

@dzwillpower
dzwillpower / gist:3128328
Created July 17, 2012 09:28
将一个String中的特殊字符用转义字符代替的方法
/**
* @return String with special XML characters escaped.
*/
public static String escapeXml(String s) {
StringBuilder sb = new StringBuilder();
for (int i = 0, len = s.length(); i < len; ++i) {
char c = s.charAt(i);
switch (c) {
case '<': sb.append("&lt;"); break;
case '>': sb.append("&gt;"); break;
@dzwillpower
dzwillpower / gist:3129556
Created July 17, 2012 14:04
把字符串的第一个字母改成大写
private static String getMethodName(String fildeName){
byte[] items = fildeName.getBytes();
items[0] = (byte)((char)items[0]-'a'+'A');;
return new String(items);
}
@dzwillpower
dzwillpower / gist:3134866
Created July 18, 2012 07:42
将毫秒转换为 00:00:00 格式的的字符串 String
/**
* 将毫秒时间转换成时分秒
* @param totalTime
* @return
*/
public String formatTime(int totalTime){
int hour = 0;
int minute = 0;
int second = 0;
second = totalTime / 1000;
@dzwillpower
dzwillpower / gist:3149218
Created July 20, 2012 07:16
解决Android下面TextView显示长度的问题 通过计算每个字符的宽度
/**
*
* @param v 需要处理的textview
* @param content 要处理的类容
* @param show_len 需要显示的长度
* @return
*/
public static String dealDetailString(TextView v,String content,float show_len){
TextPaint tpaint =v.getPaint();
String temp="";
@dzwillpower
dzwillpower / gist:3174950
Created July 25, 2012 07:40
Android 获取当前系统的语言 Language
context.getResources().getConfiguration().locale.getLanguage()
@dzwillpower
dzwillpower / DomXmlParse.java
Created September 26, 2012 11:43
xml解析 dom 解析
package com.example.xmlparse;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@dzwillpower
dzwillpower / FindOnlyRepeat.java
Last active December 14, 2015 01:09
问题描述:给定包含101个元素的数组arr,数组中元素一定属于[1,100],并且[1,100]之间的每个数都在arr中出现过。 解决方案:分析,数组中有101个元素,如果[1,100]之间的每个数出现一次,那就是100个元素了,剩下的那个元素就是唯一的重复出现的元素。我们可以通过遍历arr,得到arr中所有元素的总和,然后既然[1,100]之间的每个数出现一次,那么我们减去1+2+……+99+100的和,结果就是我们需要的唯一的重复出现的元素了。时间复杂度是O(n)。
package com.wits.practice;
/**
* 找出数组中唯一的重复元素
* @author dzwillpower
* 2013-2-21下午08:27:56
*/
public class FindOnlyRepeat {
public static void main(String[] args) {
int[] array =new int[]{1,2,3,4,4,5,6,7,8,9,10,11};
System.out.println("repeat num: "+findRepeat(array));
// Please write an sequence list implements the interface with the required
// time complexity described in the comments. The users can add the same
// element as many times as they want, but it doesn't support the null item.
// You can use any types in .NET BCL but cannot use any 3rd party libraries.
// PS: You don't need to consider the multi-threaded environment.
interface IMyList<T> : IEnumerable<T>
{
// O(1)
// Add an item at the beginning of the list.
void AddFirst(T item);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LaozhaoQ
{
// Please write an sequence list implements the interface with the required
// time complexity described in the comments. The users can add the same
// element as many times as they want, but it doesn't support the null item.