首页 > 代码库 > Java Code Style 记录
Java Code Style 记录
示例代码:
1 class Solution { 2 /** 3 * @param nums: A list of integers. 4 * @return: A list of unique permutations. 5 */ 6 public List<List<Integer>> permuteUnique(int[] nums) { 7 // Write your code here 8 ArrayList<List<Integer>> rst = new ArrayList<List<Integer>>(); 9 if (nums == null) { 10 return rst; 11 } 12 if (nums.length == 0){ 13 rst.add(new ArrayList<Integer>()); 14 return rst; 15 } 16 Arrays.sort(nums); 17 ArrayList<Integer> list = new ArrayList<Integer>(); 18 int[] visited = new int[nums.length]; 19 for (int i = 0; i < visited.length; i++) { 20 visited[i] = 0; 21 } 22 helper(rst, list, visited, nums); 23 return rst; 24 } 25 public void helper(ArrayList<List<Integer>> rst, List<Integer> list, int[] visited, int[] nums){ 26 if (list.size() == nums.length) { 27 rst.add(new ArrayList<Integer>(list)); 28 return; 29 } 30 for (int i = 0; i < nums.length; i++) { 31 if (visited[i] == 1 || (i != 0 && nums[i] == nums[i - 1] && visited[i - 1] == 0)){ 32 continue; 33 } 34 visited[i] = 1; 35 list.add(nums[i]); 36 helper(rst, list, visited, nums); 37 list.remove(list.size() - 1); 38 visited[i] = 0; 39 } 40 } 41 }
1.for后有空格;
2.if后有空格;
3.运算符前后有空格 (+-*/, ==, !=, );
4.逗号分号后有空格;
5.if for 的大括号不可省略(- -);
to do perfect……
Google Java Style:https://my.oschina.net/candiesyangyang/blog/225058
Java Code Style 记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。