- 博客(12)
- 收藏
- 关注
翻译 Single Number
Given an array of integers, every element appears twice except for one. Find that single one. 大意就是,别的数字都成双成对,只有一个数字孤身一人。【别名:寻找单身狗】 Note: Your algorithm should have a linear runtime complexity
2015-09-30 10:13:03 265
原创 Remove Element 100%哟
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. 这
2015-09-17 14:31:05 292
原创 Reverse Linked List 翻转链表
Reverse a singly linked list. 单向链表是个难点。 一开始用栈来做,结果报了内存超过了。 后来想到用指针来做。 保存第二个元素的下一个节点,让他们依次反序指向即可 /** * Definition for singly-linked list. * public class ListNode { * int val; *
2015-09-16 23:42:23 301 1
原创 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element
2015-09-16 22:10:28 270 1
原创 Excel Sheet Column Number
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ...
2015-09-16 21:49:30 283
原创 最长单词
给一个词典,找出其中所有最长的单词 样例 在词典 { "dog", "google", "facebook", "internationalization", "blabla" } 中, 最长的单词集合为 ["internationalization"] 在词典 { "like", "love", "hate", "yes" } 中
2015-09-11 11:12:50 325
原创 翻转二叉树
样例 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 通常使用递归的办法 public class Solution { /** * @param root: a TreeNode, the root of the binary tree * @
2015-09-11 10:30:12 358 1
原创 O(1)检测2的幂次
用 O(1) 时间检测整数 n 是否是 2 的幂次。 这个问题一开始我是想用求Log的方法算 public static boolean checkPowerOf2(int n) { // write your code here if(n<=0) return false; double answer=Math.log(n)/Ma
2015-09-11 09:53:53 431
原创 乱序字符串
给出一个字符串数组S,找到其中所有的乱序字符串(Anagram)。如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中。 样例 对于字符串数组 ["lint","intl","inlt","code"] 返回 ["lint","inlt","intl"] 注意 所有的字符串都只包含小写字母 先生成每个字符串的标识,即字母
2015-09-10 14:05:31 302
原创 比较两个字符串A和B,确定A中是否包含B中所有的字符。
如题 样例 给出 A = "ABCD" B = "ACD",返回 true 给出 A = "ABCD" B = "AABC", 返回 false 注意 在 A 中出现的 B 字符串里的字符不需要连续或者有序。 目前思路是分别扫描两个字符串得到两个map 比较字母出现次数,若A的每个字母次数都>=B , 则成立。同理 判断是否互为变位词也可
2015-09-09 14:08:35 6337 5
原创 JAVA GUI PART1 记事本程序 极其简易版
JMenuBar 菜单栏 JMenu 菜单项 JMenuItem 菜单项弹出来的子菜单项 FileDialog 用来访问本地文件的对话框 (frame,string,int) 以下为建议修改版记事本 import java.awt.EventQueue; public class Textbook { private JFrame frame; JMenu mnFile
2014-01-25 21:21:25 749
原创 今天开始学JAVA
新学期开始了。。告别了C开始迎接JAVA,没想到光是一个输入数字问题就把我纠结了半天,网上的方法实在是太多了,我就稍微整理一下自己看到的方便我自己以后查吧- -!... 1、 使用标准输入串对象System.in System.in.read() 返回该字节数据的ascii码 其实我觉得不太好用啊= = 2、 利用 Scanner 实现从键盘读入integer或floa
2013-03-07 18:57:46 395 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人