• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






struggleforit

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理
上一页 1 2 3 4 5 下一页

2016年12月15日

Hash Table Five Finish
摘要: (1)Word Pattern 解题思路一:使用HashMap,将字符串转化为字符串数组,并行遍历字符和字符串数组,比较它们上一次(最后一次)出现的位置,如果不相同返回false,遍历完成后返回true。 代码如下: 1 public class Solution { 2 public boolea 阅读全文
posted @ 2016-12-15 10:58 struggleforit 阅读(144) 评论(0) 推荐(0)
 

2016年12月14日

Hash Table Four
摘要: (1)Count Primes 质数(素数):在大于1 的自然数中,除了1和它本身之外,不能被任何其他整数整除。 解题思路:使用一个boolean类型的数组,从i(2) 开始循环,将小于N的i的倍数都做标记,这些数不是质数。遇到没标记的小于N的数就加一,总数即为质数的个数。 代码如下: 1 publ 阅读全文
posted @ 2016-12-14 22:05 struggleforit 阅读(98) 评论(0) 推荐(0)
 

2016年12月12日

Hash Table Three
摘要: (1)Happy Number 解题思路:使用HashSet,注意HashSet中的元素不能重复,所以不是happy number的数字要无限循环,一定要重复,就会返回false. 代码如下: 1 public class Solution { 2 public boolean isHappy(in 阅读全文
posted @ 2016-12-12 14:14 struggleforit 阅读(166) 评论(0) 推荐(0)
 

2016年12月11日

Hash Table Two
摘要: (1)Valid Anagram 解题思路: 使用一个数组,首先遍历S相应位置加1,然后遍历T,判断此时如果相应位置为零返回FALSE,否则就减一。T遍历完毕后返回true. 代码如下: 1 public class Solution { 2 public boolean isAnagram(Str 阅读全文
posted @ 2016-12-11 17:24 struggleforit 阅读(228) 评论(0) 推荐(0)
 

2016年12月10日

Hash Table Start!
摘要: (1)Island Perimeter 解题思路: 在矩阵上循环并记录岛(1)的个数;如果当前节点是岛,则检查其是否具有任何右邻居或下邻居,有的话邻居计数加1 ;岛的周长结果为islands * 4 - neighbors * 2.(乘2的原因是因为一条边属于两个邻居)。 代码如下: 1 publi 阅读全文
posted @ 2016-12-10 11:29 struggleforit 阅读(209) 评论(0) 推荐(0)
 

2016年12月6日

Array Five Finish
摘要: (1)Plus One 解题思路:模拟现实中做加法的方式,在个位加一,并考虑进位的情况。代码如下: 1 public class Solution { 2 public int[] plusOne(int[] digits) { 3 int carries = 1; 4 for (int i = d 阅读全文
posted @ 2016-12-06 11:47 struggleforit 阅读(204) 评论(0) 推荐(0)
 

2016年12月5日

Array Four
摘要: (1)Two Sum 解题思路: 使用hashmap,将(目标和-当前元素值,当前元素位置)存入,当遇到(目标和-当前元素值)的值时,取出i即可。 1 public class Solution { 2 public int[] twoSum(int[] nums, int target) { 3 阅读全文
posted @ 2016-12-05 13:16 struggleforit 阅读(187) 评论(0) 推荐(0)
 

2016年12月4日

Array Three
摘要: (1)Remove Element 注意返回的是数据长度!!! 正常思路代码如下: 1 public class Solution { 2 public int removeElement(int[] nums, int val) { 3 int count = 0; 4 for (int i = 阅读全文
posted @ 2016-12-04 14:57 struggleforit 阅读(208) 评论(0) 推荐(0)
 

2016年12月3日

Array Two(2)
摘要: (3)Remove Duplicates from Sorted Array 最优解代码如下:【注意最标准的代码风格!!!】 1 public class Solution { 2 public int removeDuplicates(int[] nums) { 3 if (nums == nul 阅读全文
posted @ 2016-12-03 21:25 struggleforit 阅读(109) 评论(0) 推荐(0)
 
Array Two
摘要: Come on,baby~ (1)Contains Duplicate 有自己的思路:两个for双重循环直接一个个比较,但肯定不是最优解。所以,使用Set中的HashSet(一种没有重复元素的无序集合),最优解如下: HashSet百度链接:http://baike.baidu.com/link?u 阅读全文
posted @ 2016-12-03 20:18 struggleforit 阅读(147) 评论(0) 推荐(0)
 
上一页 1 2 3 4 5 下一页