📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
楼主: pxu
跳转到指定楼层
上一主题 下一主题
收起左侧

刷题打卡 -pxu

🔗
 楼主| pxu 2018-5-22 09:05:56 | 只看该作者
全局:
314. Binary Tree Vertical Order Traversal
make sure the min and max data assign is opposite
    private int min = Integer.MAX_VALUE;
    private int max = Integer.MIN_VALUE;
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-22 10:32:51 | 只看该作者
全局:
#200. Number of Islands
didn't notice the grid are chars
char[][] grid
if(grid[row][col] == 1) is not going to work.
should be using:
if(grid[row][col] == '1')
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-22 14:38:44 | 只看该作者
全局:
pxu 发表于 2018-5-22 10:32
#200. Number of Islands
didn't notice the grid are chars
char[][] grid

also implemented with union find: the union function should be
parent[pu] = parent[pv];
the grid pos: should be cols*row+ col
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-23 05:25:15 | 只看该作者
全局:
#261. Graph Valid Tree
with dfs, 1st, create all the list within the map in advance
2nd: check the status in the end of dfs to make sure all the nodes are touched
with unionfind solution: union method, should be parents[pv] = pu instead of parents[v] = u;
need to check n -1 == edges.length
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-24 07:26:38 | 只看该作者
全局:
#210. Course Schedule II
should handle dependency is empty case
  if( prerequisites ==null || prerequisites.length == 0){
      for(int i= 0; i< numCourses;i++){
          res[i] = i;
      }
      return res;
  }

return empty array should be:
if(!dfs(list, i, status, resList)){
                return new int[0];
}

207. Course Schedule
use 3 status
int status[] = new int[numCourses];
used list<list<Integer>> to store the edge information

#269. Alien Dictionary
use topological and dfs
similar with course schedule
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-24 09:28:50 | 只看该作者
全局:
17. Letter Combinations of a Phone Number
mistake: should use char as the key of map
map.put('2', Arrays.asList('a','b','c'));

backtrack template:
step 1: in main method: invoked
backtrack(res, new StringBuilder(), digits, 0);

step2: in implementation method, go through  the elements and add, backtrack , remove last elements

loop the possible candidate
int index = digits.charAt(pos) - '0';
        
for(char c: keys[index].toCharArray()){
    sb.append(c);
    backtrack(res,sb,digits, pos+1);
    sb.deleteCharAt(sb.length()-1);
}
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-24 11:45:54 | 只看该作者
全局:
#215. Kth Largest Element in an Array
need quickselect to invoke the partition
in the partition, should always check left<=right on each steps!

while(left <= right){
    while(left <=right && nums[left]<= nums[pivot]) left++;
    while(left<=right && nums[right] > nums[pivot]) right--;
    if(left <= right){
        swap(nums,left, right);
    }
}
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-25 02:00:57 | 只看该作者
全局:
#127. Word Ladder
use Set<String> wordSet = new HashSet<>(wordList);
use bfs + 26 letters
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-25 02:03:53 | 只看该作者
全局:
make a wish: get the offer before the floor reach 300
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-25 11:00:41 | 只看该作者
全局:
#126 Word Ladder II
tricky:the used word can not directly removed from the dictionary. The used word is only removed when steps change.
Used to visisted and unvisited set to check and make sure the same word could be added mulitple times in the same level

used bfs to get the graph(reversed way) and dfs to get the list. check word==startword. added word first after the operation, remove it from the list;

used 26 letters to find the right candidates
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表