在一个数组 nums 中除一个数字只出现一次之外,其他数字都出现了三次。请找出那个只出现一次的数字。
示例 1:
输入:nums = [3,4,3,3]
输出:4
示例 2:
输入:nums = [9,1,7,9,7,9,7]
输出:1
限制:
1 <= nums.length <= 10000
1 <= nums[i] < 2^31
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
思路:卡诺图可以做,但是我冲不起来,就用map了。。。。。
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
private List<List<Integer>> res = new ArrayList<>();
public List<List<Integer>> pathSum(TreeNode root, int sum) {
if(root == null){
return res;
}
List<Integer> list = new ArrayList<>();
findPath(root,0,list,sum);
return res;
}
public void findPath(TreeNode node,int temp,List<Integer> list,int sum){
if(node.val + temp == sum && node.left == null & node.right == null){
list.add(node.val);
List <Integer> t = new ArrayList<>(list);
res.add(t);
list.remove(list.size() - 1);
return;
}
list.add(node.val);
if(node.left != null){
findPath(node.left,temp + node.val,list,sum);
}
if(node.right != null){
findPath(node.right,temp + node.val,list,sum);
}
list.remove(list.size() - 1);
}
}
在一个数组中,除了一个数字只出现一次外,其余数字均出现三次。本文介绍如何找到这个唯一的数字,通过示例展示输入输出,并提供了解决方案的代码实现。

722

被折叠的 条评论
为什么被折叠?



